From cbd1b777c5f53b277e240b6594179c39b9f4a1fd Mon Sep 17 00:00:00 2001 From: Jeffrey Serio <23226432+hyperreal64@users.noreply.github.com> Date: Mon, 22 Jul 2024 00:20:12 -0500 Subject: [PATCH] Refactor --- bin/server0_backup | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/bin/server0_backup b/bin/server0_backup index bcda60a..1f3d1ef 100755 --- a/bin/server0_backup +++ b/bin/server0_backup @@ -2,19 +2,38 @@ set -eu -trap "sudo -u mastodon mv /home/mastodon/db-backup.sql.temp /home/mastodon/db-backup.sql" SIGHUP SIGINT SIGQUIT SIGTERM -trap "rm -rf /tmp/log" SIGHUP SIGINT SIGQUIT SIGTERM -trap "rm -rv /home/mastodon/db-backup.sql.temp" EXIT +TEMP_DIR=$(mktemp -d) +trap 'sudo -u mastodon mv /home/mastodon/db-backup.sql.temp /home/mastodon/db-backup.sql' SIGHUP SIGINT SIGQUIT SIGTERM +trap 'rm -rf $TEMP_DIR' EXIT SIGHUP SIGINT SIGQUIT SIGTERM +trap 'rm -rv /home/mastodon/db-backup.sql.temp' EXIT sudo -u mastodon mv -v /home/mastodon/db-backup.sql /home/mastodon/db-backup.sql.temp sudo -u mastodon pg_dump -U mastodon -Fc mastodon_production -p 5432 -f /home/mastodon/db-backup.sql rclone sync -c /etc minio:server0-backup/etc/ -mkdir /tmp/log -rsync -avz /var/log/ /tmp/log -rclone sync /tmp/log minio:server0-backup/var-log/ -rm -rf /tmp/log -rclone sync -c /home/jas minio:server0-backup/home-jas/ + +mkdir "${TEMP_DIR}/log" +rsync -avz /var/log/ "${TEMP_DIR}/log" +rclone sync "${TEMP_DIR}/log"/ minio:server0-backup/var-log/ + +mkdir "${TEMP_DIR}/jas" +copy_items=( + "cdn" + "docker" + "public" + ".byobu" + ".config" + ".gmcapsulerc" + ".muttrc" + ".ssh" + ".zshrc" + ".gemini-certs" +) +for item in "${copy_items[@]}"; do + rsync -avz "/home/jas/$item" "${TEMP_DIR}/jas" +done +rclone sync -c "${TEMP_DIR}/jas"/ minio:server0-backup/home-jas/ + rclone copy -c /home/mastodon/db-backup.sql minio:server0-backup/home-mastodon/ rclone copy -c /home/mastodon/live/.env.production minio:server0-backup/home-mastodon/