Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore on PSQL does not replace existing data #3

Open
abhi1693 opened this issue Dec 12, 2023 · 0 comments
Open

Restore on PSQL does not replace existing data #3

abhi1693 opened this issue Dec 12, 2023 · 0 comments

Comments

@abhi1693
Copy link

abhi1693 commented Dec 12, 2023

When I run restore, no data is changed and the restore logs have alots of errors due to conflicts. In order to get a successful restore, I have perform the following CLI commands first

  1. Revoke new connections
psql -U webadmin -d postgres -c "REVOKE CONNECT ON DATABASE dbname FROM PUBLIC, username;"
  1. Kill existing sessions
psql -U webadmin -d postgres -c "SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE pid <> pg_backend_pid() AND datname = 'dbname'"
  1. Drop the database
psql -U webadmin -d postgres -c "drop database dbname"
  1. Perform restore via the addon

Note: Since we have our application level DB user, we need to make sure that it does not reconnect during the restore process so that I can perform an uninterrupted restore.

Logs from restore without performing the above steps:

[19:26:31]:> cmd: echo $(date) %(envName) Restoring the snapshot $(cat /root/.backupid),SNAPSHOT_ID=$(RESTIC_PASSWORD=$(cat /root/.backupedenv) restic -r /opt/backup/$(cat /root/.backupedenv) snapshots|grep $(cat /root/.backupid)|awk '{print $1}'),[ -n "${SNAPSHOT_ID}" ] || false,source /etc/jelastic/metainf.conf,RESTIC_PASSWORD=$(cat /root/.backupedenv) restic -r /opt/backup/$(cat /root/.backupedenv) restore ${SNAPSHOT_ID} --target /,if [ "$COMPUTE_TYPE" == "redis" ]; then rm -f /root/redis-restore.sh; wget -O /root/redis-restore.sh %(baseUrl)/scripts/redis-restore.sh; chmod +x /root/redis-restore.sh; bash /root/redis-restore.sh; else true; fi,[ "$COMPUTE_TYPE" == "postgres" ] && PGPASSWORD=%(dbpass) psql -U %(dbuser) -d postgres < /root/db_backup.sql || true,if [ "$COMPUTE_TYPE" == "mariadb" ] || [ "$COMPUTE_TYPE" == "mysql" ] || [ "$COMPUTE_TYPE" == "percona" ]; then mysql -h localhost -u %(dbuser) -p%(dbpass) --force < /root/db_backup.sql; else true; fi,jem service restart,if [ -n "$REPLICA_PSWD" ] && [ -n "$REPLICA_USER" ] ; then wget %(baseUrl)/scripts/setupUser.sh -O /root/setupUser.sh &>> /var/log/run.log; bash /root/setupUser.sh ${REPLICA_USER} ${REPLICA_PSWD} %(userEmail) %(envName) %(userSession); fi,{"nodeId":"3065","envName":"env-3489800","baseUrl":"https://raw.githubusercontent.com/jelastic-jps/database-backup-addon/master","dbuser":"webadmin","dbpass":"NLNiHxDBX2","userEmail":"asaharan@onemindservices.com","userSession":"21xbab3dc22fda4fdbea96e417e259dc8f0"}
[19:26:43]:> cmd.response: {"result":0,"responses":[{"result":0,"errOut":"ERROR:  role \"netbox\" already exists\nERROR:  role \"postgres\" already exists\nERROR:  role \"webadmin\" already exists\nERROR:  database \"netbox\" already exists\nERROR:  relation \"auth_group\" already exists\nERROR:  relation \"auth_group_id_seq\" already exists\nERROR:  relation \"auth_group_permissions\" already exists\nERROR:  relation \"auth_group_permissions_id_seq\" already exists\nERROR:  relation \"auth_permission\" already exists\nERROR:  relation \"auth_permission_id_seq\" already exists\nERROR:  relation \"auth_user\" already exists\nERROR:  relation \"auth_user_groups\" already exists\nERROR:  relation \"auth_user_groups_id_seq\" already exists\nERROR:  relation \"auth_user_id_seq\" already exists\nERROR:  relation \"auth_user_user_permissions\" already exists\nERROR:  relation \"auth_user_user_permissions_id_seq\" already exists\nERROR:  relation \"circuits_circuit\" already exists\nERROR:  relation \"circuits_circuit_id_seq\" already exists\nERROR:  relation \"circuits_circuittermination\" already exists\nERROR:  relation \"circuits_circuittermination_id_seq\" already exists\nERROR:  relation \"circuits_circuittype\" already exists\nERROR:  relation \"circuits_circuittype_id_seq\" already exists\nERROR:  relation \"circuits_provider\" already exists\nERROR:  relation \"circuits_provider_asns\" already exists\nERROR:  relation \"circuits_provider_asns_id_seq\" already exists\nERROR:  relation \"circuits_provider_id_seq\" already exists\nERROR:  relation \"circuits_providernetwork\" already exists\nERROR:  relation \"circuits_providernetwork_id_seq\" already exists\nERROR:  relation \"dcim_cable\" already exists\nERROR:  relation \"dcim_cable_id_seq\" already exists\nERROR:  relation \"dcim_cablepath\" already exists\nERROR:  relation \"dcim_cablepath_id_seq\" already exists\nERROR:  relation \"dcim_cabletermination\" already exists\nERROR:  relation \"dcim_cabletermination_id_seq\" already exists\nERROR:  relation \"dcim_consoleport\" already exists\nERROR:  relation \"dcim_consoleport_id_seq\" already exists\nERROR:  relation \"dcim_consoleporttemplate\" already exists\nERROR:  relation \"dcim_consoleporttemplate_id_seq\" already exists\nERROR:  relation \"dcim_consoleserverport\" already exists\nERROR:  relation \"dcim_consoleserverport_id_seq\" already exists\nERROR:  relation \"dcim_consoleserverporttemplate\" already exists\nERROR:  relation \"dcim_consoleserverporttemplate_id_seq\" already exists\nERROR:  relation \"dcim_device\" already exists\nERROR:  relation \"dcim_device_id_seq\" already exists\nERROR:  relation \"dcim_devicebay\" already exists\nERROR:  relation \"dcim_devicebay_id_seq\" already exists\nERROR:  relation \"dcim_devicebaytemplate\" already exists\nERROR:  relation \"dcim_devicebaytemplate_id_seq\" already exists\nERROR:  relation \"dcim_devicerole\" already exists\nERROR:  relation \"dcim_devicerole_id_seq\" already exists\nERROR:  relation \"dcim_devicetype\" already exists\nERROR:  relation \"dcim_devicetype_id_seq\" already exists\nERROR:  relation \"dcim_frontport\" already exists\nERROR:  relation \"dcim_frontport_id_seq\" already exists\nERROR:  relation \"dcim_frontporttemplate\" already exists\nERROR:  relation \"dcim_frontporttemplate_id_seq\" already exists\nERROR:  relation \"dcim_interface\" already exists\nERROR:  relation \"dcim_interface_id_seq\" already exists\nERROR:  relation \"dcim_interface_tagged_vlans\" already exists\nERROR:  relation \"dcim_interface_tagged_vlans_id_seq\" already exists\nERROR:  relation \"dcim_interface_vdcs\" already exists\nERROR:  relation \"dcim_interface_vdcs_id_seq\" already exists\nERROR:  relation \"dcim_interface_wireless_lans\" already exists\nERROR:  relation \"dcim_interface_wireless_lans_id_seq\" already exists\nERROR:  relation \"dcim_interfacetemplate\" already exists\nERROR:  relation \"dcim_interfacetemplate_id_seq\" already exists\nERROR:  relation \"dcim_inventoryitem\" already exists\nERROR:  relation \"dcim_inventoryitem_id_seq\" already exists\nERROR:  relation \"dcim_inventoryitemrole\" already exists\nERROR:  relation \"dcim_inventoryitemrole_id_seq\" already exists\nERROR:  relation \"dcim_inventoryitemtemplate\" already exists\nERROR:  relation \"dcim_inventoryitemtemplate_id_seq\" already exists\nERROR:  relation \"dcim_location\" already exists\nERROR:  relation \"dcim_location_id_seq\" already exists\nERROR:  relation \"dcim_manufacturer\" already exists\nERROR:  relation \"dcim_manufacturer_id_seq\" already exists\nERROR:  relation \"dcim_module\" already exists\nERROR:  relation \"dcim_m
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant