#!/bin/bash # # need utils smbfs declare -a DIR2CIFS="" # répertoire local vers lequel sera monté le partage réseau declare -a RSYNC_OPTIONS="-acRz --delete-during --delete-excluded --ignore-errors --force --numeric-ids --partial --stats --timeout=900" declare -a DIR2BCKP="()" # ne pas modifier ! DIR2BCKP[0]="/etc/" DIR2BCKP[1]="/home/" DIR2BCKP[2]="/root/" declare -i NB_ARCHIVES=7 # ------------- system commands used by this script -------------------- declare -i count=${#DIR2BCKP[@]} declare -i i=0 declare -i x=$(expr $NB_ARCHIVES - 1) if (( `id -u` != 0 )); then { $ECHO "Sorry, must be root. Exiting..."; exit; } fi mount "$DIR2CIFS/" # step 1: delete the oldest snapshot, if it exists: if [ -d "$DIR2CIFS/daily.$NB_ARCHIVES" ] ; then rm -rf "$DIR2CIFS/daily.$NB_ARCHIVES" ; fi ; # step 2: shift the middle snapshots(s) back by one, if they exist while [ "$x" -gt 0 ]; do if [ -d "$DIR2CIFS/daily.$x" ]; then y=$(expr $x + 1) mv "$DIR2CIFS/daily.$x" "$DIR2CIFS/daily.$y" fi x=$(($x-1)) done #step 3: daily.0 -> daily.1 if [ -d "$DIR2CIFS/daily.0" ]; then cp -al "$DIR2CIFS/daily.0" "$DIR2CIFS/daily.1" fi #step 4: if not exists daily.0 [ -d "$DIR2CIFS/daily.0" ] && mkdir "$DIR2CIFS/daily.0" #step 5: rsync cd $DIR2CIFS while [ "$i" -lt "$count" ]; do rsync $RSYNC_OPTIONS "${DIR2BCKP[$i]}" "$DIR2CIFS/daily.0" i=$(($i+1)) done #step 6: uptime mtime touch "$DIR2CIFS/daily.0" umount "$DIR2CIFS/"