From 0dc77b3d5409b0fa4332d60f8bfd70b6d3875bc7 Mon Sep 17 00:00:00 2001 From: simon Date: Sat, 25 Mar 2023 12:49:12 +0700 Subject: [PATCH] delete pg source files for dbsync --- helper_scripts/db_sync.sh | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/helper_scripts/db_sync.sh b/helper_scripts/db_sync.sh index 51411e3..3fcbdcb 100755 --- a/helper_scripts/db_sync.sh +++ b/helper_scripts/db_sync.sh @@ -12,17 +12,25 @@ echo "---------------------------------------" printf "\n -> backup\n" ssh $remote_host 'docker exec postgres pg_dump -U aqi | gzip > backup.gz' printf "\n -> download\n" -rsync --progress -r --delete-after -e ssh $remote_host:backup.gz /tmp/backup.gz +rsync --progress -r --remove-source-files -e ssh $remote_host:backup.gz /tmp/backup.gz # sync printf "\n -> sync\n" -rsync --progress -r --delete-after /tmp/backup.gz -e ssh $local_host:backup +rsync --progress -r --remove-source-files /tmp/backup.gz -e ssh $local_host:backup ssh $local_host 'gzip -df backup/backup.gz' # replace printf "\n -> replace\n" -ssh $local_host "docker exec -i postgres psql -U aqi -c 'DROP TABLE IF EXISTS aqi;'" -ssh $local_host "docker exec -i postgres psql -U aqi -c 'DROP TABLE IF EXISTS weather;'" + +ssh $local_host "docker exec -i postgres psql -U aqi -c \ + 'DROP SCHEMA public CASCADE;'" +ssh $local_host "docker exec -i postgres psql -U aqi -c \ + 'CREATE SCHEMA public;'" + +ssh $local_host "docker exec -i postgres psql -U aqi -c \ + 'DROP TABLE IF EXISTS aqi;'" +ssh $local_host "docker exec -i postgres psql -U aqi -c \ + 'DROP TABLE IF EXISTS weather;'" ssh $local_host 'docker exec -i postgres psql -U aqi -d aqi < backup/backup' ssh $local_host "trash backup/backup" printf "\n -> done\n"