Skip to content

Commit

Permalink
Petites améliorations des scripts de sauvegarde
Browse files Browse the repository at this point in the history
  • Loading branch information
philippemilink committed Jul 14, 2024
1 parent ab5c146 commit d03f82a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
2 changes: 1 addition & 1 deletion docs/backup.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ borg list beta-backup:/chemin | less
# mensuelle des 6 derniers mois.
# `-n` pour simuler la suppression et voir les sauvegardes qui vont être
# supprimées.
borg prune --keep-within 3m -m 6 --list --stats -n beta-backup:/chemin
borg prune --keep-within 3m -m 6 --list --stats --progress -n beta-backup:/chemin
# Enlever l'éventuel --append-only dans .ssh/authorized_keys
borg compact --progress beta-backup:/chemin # pour vraiment libérer l'espace
# Remettre l'éventuel --append-only dans .ssh/authorized_keys
Expand Down
37 changes: 17 additions & 20 deletions roles/backup/files/prod/backups.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ set -eu

readonly BORG126=/usr/local/bin/borg1.2.6
readonly BORG1117=/usr/local/bin/borg
BACKUP_DATE=`date '+%Y%m%d-%H%M'`
DATA_SAVED_DIR=/opt/zds/data
DB_SAVED_DIR=/var/backups/mysql
readonly BORG_OPTIONS="--list --verbose --filter AME --show-rc --compression zstd,6 --exclude-caches --info" # --stats
readonly BACKUP_DATE=`date '+%Y%m%d-%H%M'`
readonly DATA_SAVED_DIR=/opt/zds/data
readonly DB_SAVED_DIR=/var/backups/mysql

db_local_backup()
{
Expand Down Expand Up @@ -46,29 +47,22 @@ db_local_backup()
backup2beta2023()
{
echo "Backup data to the 2023 beta server..."
$BORG126 create \
--verbose \
--filter AME \
--list \
--stats \
--show-rc \
--compression zstd,6 \
--exclude-caches \
date
$BORG126 create $BORG_OPTIONS \
beta-backup-2023:/opt/sauvegarde/data::$BACKUP_DATE \
$DATA_SAVED_DIR
rc_data=$?
date

echo "Backup database to the 2023 beta server..."
$BORG126 create \
--verbose \
--filter AME \
--list \
--stats \
--show-rc \
--compression zstd,6 \
--exclude-caches \
--info \
date
$BORG126 create $BORG_OPTIONS \
beta-backup-2023:/opt/sauvegarde/db::$BACKUP_DATE \
$DB_SAVED_DIR
rc_db=$?
date

return $((rc_data+rc_db))
}


Expand Down Expand Up @@ -132,3 +126,6 @@ fi
echo "End of script ($(date))"
# Big separator in log between executions of the script:
echo "#######################################################################################################################"
echo
echo
echo
9 changes: 8 additions & 1 deletion roles/backup/templates/beta/cleaning.sh.j2
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

set -e

echo "Starting script ($(date))"

readonly DATA_DB_RULES="--keep-within 30d -w 6 -m 3"
readonly BORG_BINARY=/usr/local/bin/borg1.2.6
readonly BORG_PRUNE="$BORG_BINARY prune --list --stats"
readonly BORG_COMPACT="$BORG_BINARY compact --verbose"


echo "##########################################################################"
echo "Starting script ($(date))"

echo "** data ** ($(date))"
sudo -u zds-prod $BORG_PRUNE $DATA_DB_RULES /opt/sauvegarde/data/
sudo -u zds-prod $BORG_COMPACT /opt/sauvegarde/data/
Expand All @@ -25,3 +28,7 @@ curl -s -m 10 --retry 5 {{ secrets.healthcheck_urls.backup_cleaning }}
echo # to make a newline after the "OK" written by curl

echo "End of script ($(date))"
echo "##########################################################################"
echo
echo
echo

0 comments on commit d03f82a

Please sign in to comment.