Browse Source

[backup] shellcheck

master
Matteo Cypriani 1 year ago
parent
commit
ae8456fa96
3 changed files with 20 additions and 16 deletions
  1. 7
    7
      backup/backup_sites_mysql.sh
  2. 2
    1
      backup/btrfs_snapshot_date.sh
  3. 11
    8
      backup/obstinate-rsync.sh

+ 7
- 7
backup/backup_sites_mysql.sh View File

@@ -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

+ 2
- 1
backup/btrfs_snapshot_date.sh View File

@@ -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"

+ 11
- 8
backup/obstinate-rsync.sh View File

@@ -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

Loading…
Cancel
Save