Fix gitea_backup.sh script to correctly include datadir

This commit is contained in:
flyingscorpio@clevo 2022-04-13 23:27:19 +02:00
parent e0820766ae
commit 196aa1ed18

View file

@ -10,6 +10,7 @@ IFS="$(printf '\n\t')"
PROGRAM="${0##*/}" PROGRAM="${0##*/}"
INSTALL_DIR=/usr/local/bin INSTALL_DIR=/usr/local/bin
TMP_DIR=/home/git/tmp TMP_DIR=/home/git/tmp
WORK_DIR=/var/lib/gitea/
DATA_DIR=/var/lib/gitea/data/ DATA_DIR=/var/lib/gitea/data/
LOG_DIR=/var/lib/gitea/log/ LOG_DIR=/var/lib/gitea/log/
REPO_DIR=/home/git/gitea-repositories/ REPO_DIR=/home/git/gitea-repositories/
@ -50,7 +51,7 @@ do_backup() {
stop_service stop_service
output_dump_file="$DUMP_DIR/gitea-dump-$(date +'%Y%m%d').zip" output_dump_file="$DUMP_DIR/gitea-dump-$(date +'%Y%m%d').zip"
cd "$INSTALL_DIR" || exit 1 cd "$INSTALL_DIR" || exit 1
./gitea dump -V -f "$output_dump_file" -c "$CONFIG_FILE" -t "$TMP_DIR" --skip-attachment-data --skip-lfs-data -w "$HOME" ./gitea dump -V -f "$output_dump_file" -c "$CONFIG_FILE" -t "$TMP_DIR" --skip-attachment-data --skip-lfs-data -w "$WORK_DIR"
chmod 640 "$output_dump_file" # Make the file readable by group for scp to different host by different user chmod 640 "$output_dump_file" # Make the file readable by group for scp to different host by different user
restart_service restart_service
echo "Done." echo "Done."
@ -63,14 +64,13 @@ do_restore() {
chmod 600 "$zip_file" # Backup has changed permissions, restore them here chmod 600 "$zip_file" # Backup has changed permissions, restore them here
echo "Unzipping $zip_file..." && unzip "$zip_file" -d "$zip_dir" && echo " OK." echo "Unzipping $zip_file..." && unzip "$zip_file" -d "$zip_dir" && echo " OK."
cd "$zip_dir" || exit 1 cd "$zip_dir" || exit 1
chmod 660 "$CONFIG_FILE"
echo -n "Restoring $CONFIG_FILE..." && mv -f app.ini "$CONFIG_FILE" && echo " OK." echo -n "Restoring $CONFIG_FILE..." && mv -f app.ini "$CONFIG_FILE" && echo " OK."
chmod 640 "$CONFIG_FILE" echo -n "Restoring $DATA_DIR..." && mv -f data/* "$DATA_DIR" && rmdir data && echo " OK."
echo -n "Restoring $DATA_DIR..." && mv -f data/* "$DATA_DIR" && echo " OK." echo -n "Restoring $LOG_DIR..." && mv -f log/* "$LOG_DIR" && rmdir log && echo " OK."
echo -n "Restoring $LOG_DIR..." && mv -f log/* "$LOG_DIR" && echo " OK." echo -n "Restoring $REPO_DIR..." && mkdir -p "$REPO_DIR" && mv -f repos/* "$REPO_DIR" && rmdir repos && echo " OK."
echo -n "Restoring $REPO_DIR..." && mkdir -p "$REPO_DIR" && mv -f repos/* "$REPO_DIR" && echo " OK."
echo -n "Changing ownership..." && chown -R git:git "$CONFIG_FILE" /var/lib/gitea && echo " OK." echo -n "Changing ownership..." && chown -R git:git "$CONFIG_FILE" /var/lib/gitea && echo " OK."
echo -n "Restoring MySQL database..." && mysql --default-character-set=utf8mb4 -u"$MYSQL_USER" -p"$MYSQL_PW" "$MYSQL_DB" < gitea-db.sql && echo " OK." echo -n "Restoring MySQL database..." && mysql --default-character-set=utf8mb4 -u"$MYSQL_USER" -p"$MYSQL_PW" "$MYSQL_DB" < gitea-db.sql && rm gitea-db.sql && echo " OK."
rmdir "$zip_dir"
restart_service restart_service
regenerate_hooks regenerate_hooks
echo "Done." echo "Done."