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"
43 43
 
44 44
 umask 077
45 45
 
46
-DATE=`date +'%Y-%m-%d'` # date au format année-mois-jour
47
-REP_SAUV="$REP_TMP_SAUV"/$DATE
46
+DATE="$(date +'%Y-%m-%d')" # date au format année-mois-jour
47
+REP_SAUV="$REP_TMP_SAUV/$DATE"
48 48
 
49 49
 # Création du répertoire de destination et du répertoire final
50 50
 mkdir -p "$REP_SAUV" || exit 2
@@ -52,16 +52,16 @@ mkdir -p "$REP_MV_SAUV" || exit 2
52 52
 
53 53
 # Sauvegarde des bases de données
54 54
 for BASE in $BASES ; do
55
-	FICH_DUMP="$REP_SAUV"/${BASE}_$DATE.dump
56
-	mysqldump --lock-tables -u $USER -p"$PASS" -B $BASE > "$FICH_DUMP"
57
-	$COMPRESS $COMPRESS_LEVEL "$FICH_DUMP" # On compresse après avoir terminé le dump afin que la BDD ne soit pas verrouillée trop longtemps.
55
+	FICH_DUMP="$REP_SAUV/${BASE}_${DATE}.dump"
56
+	mysqldump --lock-tables -u "$USER" -p"$PASS" -B "$BASE" > "$FICH_DUMP"
57
+	$COMPRESS "$COMPRESS_LEVEL" "$FICH_DUMP" # On compresse après avoir terminé le dump afin que la BDD ne soit pas verrouillée trop longtemps.
58 58
 done
59 59
 
60 60
 # Sauvegarde des répertoires
61 61
 for REP in $REPS ; do
62 62
 	if [ -e $REP ] ; then
63
-		ARCH="$REP_SAUV"/`basename "$REP"`_$DATE
64
-		tar cf - $REP | $COMPRESS -9 > "$ARCH".tar.$ZEXT
63
+		ARCH="$REP_SAUV/$(basename "$REP")_$DATE"
64
+		tar cf - $REP | $COMPRESS -9 > "$ARCH".tar."$ZEXT"
65 65
 	else
66 66
 		echo "Erreur ! Le fichier « $REP » n'existe pas." >&2
67 67
 	fi

+ 2
- 1
backup/btrfs_snapshot_date.sh View File

@@ -19,4 +19,5 @@ SV="backupsv"
19 19
 
20 20
 mount "$ROOT"
21 21
 SV="$ROOT/$SV"
22
-btrfs subvolume snapshot "$SV" "$SV"_$(date '+%Y-%m-%dT%H:%M:%S')
22
+DATE="$(date '+%Y-%m-%dT%H:%M:%S')"
23
+btrfs subvolume snapshot "$SV" "$SV"_"$DATE"

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

@@ -11,9 +11,9 @@
11 11
 # Transfers a single directory to a remote host using rsync. The
12 12
 # transfer is retried until it succeeds.
13 13
 
14
-# Any of the protocol supported by rsync, with the "://" (blank to use
14
+# Any of the protocol supported by rsync, with the "://" (comment-out to use
15 15
 # SSH):
16
-PROTO=rsync://
16
+#PROTO=rsync://
17 17
 # Remote backup host:
18 18
 HOST=vicious
19 19
 # Destination of the backup on the remote host:
@@ -23,12 +23,15 @@ REMOTE_DIR=/backup
23 23
 LOCAL_DIR="$HOME"
24 24
 # File where the excludes patterns are stored (one per line):
25 25
 EXCLUDES="$HOME/.backup-excludes"
26
-# Blank to keep the locally deleted files on the remote host (you can
26
+# Remove --delete to keep the locally deleted files on the remote host (you can
27 27
 # also set to --delete-after or --delete-before):
28
-DELETE="--delete"
28
+RSYNC_OPTS="-av --delete"
29 29
 
30
-false
31
-until [ $? -eq 0 ] ; do
32
-	rsync -av ${DELETE} --exclude-from="$EXCLUDES" \
33
-		"$LOCAL_DIR" ${PROTO}://${HOST}:"$REMOTE_DIR"
30
+# shellcheck disable=2086
31
+until rsync $RSYNC_OPTS --exclude-from="$EXCLUDES" \
32
+    "$LOCAL_DIR" "${PROTO}${HOST}:$REMOTE_DIR"
33
+do
34
+    echo "Retrying..."
34 35
 done
36
+
37
+# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4

Loading…
Cancel
Save