From 466c4509df3d5c2027f205b8069555ec869ff918 Mon Sep 17 00:00:00 2001 From: Tunui Franken Date: Sun, 30 Mar 2025 14:21:07 +0200 Subject: [PATCH] forgejo-backup: Don't zip the archive to use it with borgmatic --- inventory/group_vars/lime2servers | 2 +- roles/forgejo/templates/forgejo-backup.sh.j2 | 18 ++++++++---------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/inventory/group_vars/lime2servers b/inventory/group_vars/lime2servers index f03b5b6..03e678a 100644 --- a/inventory/group_vars/lime2servers +++ b/inventory/group_vars/lime2servers @@ -7,4 +7,4 @@ borgmatic_hooks: before_backup: - sudo -Hiu git /usr/local/bin/forgejo-backup.sh backup after_backup: - - sudo -Hiu git /usr/local/bin/forgejo-backup.sh prune 1 + - sudo -Hiu git /usr/local/bin/forgejo-backup.sh prune 0 diff --git a/roles/forgejo/templates/forgejo-backup.sh.j2 b/roles/forgejo/templates/forgejo-backup.sh.j2 index 897b3a7..bae0448 100644 --- a/roles/forgejo/templates/forgejo-backup.sh.j2 +++ b/roles/forgejo/templates/forgejo-backup.sh.j2 @@ -60,8 +60,6 @@ do_backup() { tar --delete -f "$output_dump_file" forgejo-db.sql tar --append -f "$output_dump_file" "$(basename $mysql_dump_file)" rm "$mysql_dump_file" - chmod 640 "$output_dump_file" # Make the file readable by group for scp to different host by different user - gzip "$output_dump_file" echo "Done." } @@ -69,14 +67,14 @@ do_restore() { echo "Restoring Forgejo backup..." start_dir="$PWD" tar_file="$1" - tar_dir="${tar_file%.tar.gz}" # Remove file extension - chmod 600 "$tar_file" # Backup has changed permissions, restore them here - echo "Extracting $tar_file..." && mkdir "$tar_dir" && tar xvzf "$tar_file" -C "$tar_dir" && echo " OK." + tar_dir="${tar_file%.tar}" # Remove file extension + stop_service + echo -n "Extracting $tar_file..." && mkdir "$tar_dir" && tar xf "$tar_file" -C "$tar_dir" && echo " OK." cd "$tar_dir" || exit 1 - rm app.ini - echo -n "Restoring $DATA_DIR..." && rsync -avz --delete data/ "$DATA_DIR" && rm -rf data && echo " OK." - echo -n "Restoring $LOG_DIR..." && rsync -avz log/ "$LOG_DIR" && rm -rf log && echo " OK." - echo -n "Restoring $REPO_DIR..." && mkdir -p "$REPO_DIR" && rsync -avz --delete repos/ "$REPO_DIR" && rm -rf repos && echo " OK." + rm app.ini # Deployed with Ansible + echo -n "Restoring $DATA_DIR..." && rsync -az --delete data/ "$DATA_DIR" && rm -rf data && echo " OK." + echo -n "Restoring $LOG_DIR..." && rsync -az log/ "$LOG_DIR" && rm -rf log && echo " OK." + echo -n "Restoring $REPO_DIR..." && mkdir -p "$REPO_DIR" && rsync -az --delete repos/ "$REPO_DIR" && rm -rf repos && echo " OK." echo -n "Changing ownership..." && chown -R git:git "$CONFIG_FILE" "$WORK_DIR" && echo " OK." echo -n "Restoring MySQL database..." && mysql --default-character-set=utf8mb4 -u"$MYSQL_USER" -p"$MYSQL_PW" "$MYSQL_DB" < forgejo-db.sql && rm forgejo-db.sql && echo " OK." cd "$start_dir" || exit 1 @@ -88,7 +86,7 @@ do_restore() { do_prune() { echo "Pruning Forgejo backups and keeping $1 of them..." - dumps=("$DUMP_DIR"/forgejo-dump-*.tar.gz) + dumps=("$DUMP_DIR"/forgejo-dump-*.tar) nb_of_dumps="${#dumps[@]}" nb_to_keep="$1" nb_to_prune=$((nb_of_dumps - nb_to_keep))