From ae8456fa9678a8ccedb90e86f98af05c56bc29c6 Mon Sep 17 00:00:00 2001 From: Matteo Cypriani Date: Wed, 11 Apr 2018 22:31:14 +0200 Subject: [PATCH] [backup] shellcheck --- backup/backup_sites_mysql.sh | 14 +++++++------- backup/btrfs_snapshot_date.sh | 3 ++- backup/obstinate-rsync.sh | 19 +++++++++++-------- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/backup/backup_sites_mysql.sh b/backup/backup_sites_mysql.sh index c8dcaca..7dd3e0e 100755 --- a/backup/backup_sites_mysql.sh +++ b/backup/backup_sites_mysql.sh @@ -43,8 +43,8 @@ ZEXT="xz" umask 077 -DATE=`date +'%Y-%m-%d'` # date au format année-mois-jour -REP_SAUV="$REP_TMP_SAUV"/$DATE +DATE="$(date +'%Y-%m-%d')" # date au format année-mois-jour +REP_SAUV="$REP_TMP_SAUV/$DATE" # Création du répertoire de destination et du répertoire final mkdir -p "$REP_SAUV" || exit 2 @@ -52,16 +52,16 @@ mkdir -p "$REP_MV_SAUV" || exit 2 # Sauvegarde des bases de données for BASE in $BASES ; do - FICH_DUMP="$REP_SAUV"/${BASE}_$DATE.dump - mysqldump --lock-tables -u $USER -p"$PASS" -B $BASE > "$FICH_DUMP" - $COMPRESS $COMPRESS_LEVEL "$FICH_DUMP" # On compresse après avoir terminé le dump afin que la BDD ne soit pas verrouillée trop longtemps. + FICH_DUMP="$REP_SAUV/${BASE}_${DATE}.dump" + mysqldump --lock-tables -u "$USER" -p"$PASS" -B "$BASE" > "$FICH_DUMP" + $COMPRESS "$COMPRESS_LEVEL" "$FICH_DUMP" # On compresse après avoir terminé le dump afin que la BDD ne soit pas verrouillée trop longtemps. done # Sauvegarde des répertoires for REP in $REPS ; do if [ -e $REP ] ; then - ARCH="$REP_SAUV"/`basename "$REP"`_$DATE - tar cf - $REP | $COMPRESS -9 > "$ARCH".tar.$ZEXT + ARCH="$REP_SAUV/$(basename "$REP")_$DATE" + tar cf - $REP | $COMPRESS -9 > "$ARCH".tar."$ZEXT" else echo "Erreur ! Le fichier « $REP » n'existe pas." >&2 fi diff --git a/backup/btrfs_snapshot_date.sh b/backup/btrfs_snapshot_date.sh index 83de87d..135a3e2 100755 --- a/backup/btrfs_snapshot_date.sh +++ b/backup/btrfs_snapshot_date.sh @@ -19,4 +19,5 @@ SV="backupsv" mount "$ROOT" SV="$ROOT/$SV" -btrfs subvolume snapshot "$SV" "$SV"_$(date '+%Y-%m-%dT%H:%M:%S') +DATE="$(date '+%Y-%m-%dT%H:%M:%S')" +btrfs subvolume snapshot "$SV" "$SV"_"$DATE" diff --git a/backup/obstinate-rsync.sh b/backup/obstinate-rsync.sh index b8e9eca..e05a9a1 100755 --- a/backup/obstinate-rsync.sh +++ b/backup/obstinate-rsync.sh @@ -11,9 +11,9 @@ # Transfers a single directory to a remote host using rsync. The # transfer is retried until it succeeds. -# Any of the protocol supported by rsync, with the "://" (blank to use +# Any of the protocol supported by rsync, with the "://" (comment-out to use # SSH): -PROTO=rsync:// +#PROTO=rsync:// # Remote backup host: HOST=vicious # Destination of the backup on the remote host: @@ -23,12 +23,15 @@ REMOTE_DIR=/backup LOCAL_DIR="$HOME" # File where the excludes patterns are stored (one per line): EXCLUDES="$HOME/.backup-excludes" -# Blank to keep the locally deleted files on the remote host (you can +# Remove --delete to keep the locally deleted files on the remote host (you can # also set to --delete-after or --delete-before): -DELETE="--delete" +RSYNC_OPTS="-av --delete" -false -until [ $? -eq 0 ] ; do - rsync -av ${DELETE} --exclude-from="$EXCLUDES" \ - "$LOCAL_DIR" ${PROTO}://${HOST}:"$REMOTE_DIR" +# shellcheck disable=2086 +until rsync $RSYNC_OPTS --exclude-from="$EXCLUDES" \ + "$LOCAL_DIR" "${PROTO}${HOST}:$REMOTE_DIR" +do + echo "Retrying..." done + +# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4