use f00king functions!
use ALL and EVERY backup (daily.1 to daily.$$MAX_ROTATE) for --link-dest
This commit is contained in:
parent
bfa5c980a1
commit
caa179efa4
106
remote-backup
106
remote-backup
@ -60,8 +60,20 @@ then
|
|||||||
fi
|
fi
|
||||||
###END: generic tool checker
|
###END: generic tool checker
|
||||||
|
|
||||||
for config in /etc/remote-backup/*/config
|
while getopts 'e:h' opt
|
||||||
do
|
do
|
||||||
|
case $opt in
|
||||||
|
e)
|
||||||
|
EMERG="$OPTARG"
|
||||||
|
;;
|
||||||
|
h)
|
||||||
|
help
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
doBackup() {
|
||||||
|
config="$1"
|
||||||
if [ ! -e "$config" ]
|
if [ ! -e "$config" ]
|
||||||
then
|
then
|
||||||
echo "No backups defined, dying." >&2
|
echo "No backups defined, dying." >&2
|
||||||
@ -70,16 +82,7 @@ do
|
|||||||
source /etc/remote-backup/defaults.conf
|
source /etc/remote-backup/defaults.conf
|
||||||
source "$config"
|
source "$config"
|
||||||
|
|
||||||
echo "Debut de backup de ${REMOTE_LOCATION} vers ${SNAPSHOT_RW}/${NAME}/ a $(date)"
|
echo "Debut de backup de ${REMOTE_LOCATION} vers ${SNAPSHOT_RW}/${NAME}/ a $(date +"%H:%M, le %d/%m/%Y")"
|
||||||
|
|
||||||
# ------------- the script itself --------------------------------------
|
|
||||||
|
|
||||||
# make sure we're running as root
|
|
||||||
if [ ! $UID -eq 0 ]
|
|
||||||
then
|
|
||||||
echo "Sorry, must be root. Exiting..."
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ "$REMOUNT" == "true" ]]
|
if [[ "$REMOUNT" == "true" ]]
|
||||||
then
|
then
|
||||||
@ -87,8 +90,8 @@ do
|
|||||||
$MOUNT -o remount,rw "$MOUNT_DEVICE" "$SNAPSHOT_RW" ;
|
$MOUNT -o remount,rw "$MOUNT_DEVICE" "$SNAPSHOT_RW" ;
|
||||||
if (( $? ))
|
if (( $? ))
|
||||||
then
|
then
|
||||||
echo "snapshot: could not remount $SNAPSHOT_RW readwrite"
|
echo "snapshot: could not remount $SNAPSHOT_RW readwrite" >&2
|
||||||
exit
|
return 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -97,8 +100,31 @@ do
|
|||||||
mkdir -p "$SNAPSHOT_RW/$NAME"
|
mkdir -p "$SNAPSHOT_RW/$NAME"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# rotating snapshots of /home (fixme: this should be more general)
|
if [[ "$2" == emerg ]]
|
||||||
|
then
|
||||||
|
runBackup emerg.$(date +%Y%m%d%H%M)
|
||||||
|
else
|
||||||
|
rotateBackup
|
||||||
|
runBackup daily.0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# now remount the RW snapshot mountpoint as readonly
|
||||||
|
if [[ "$REMOUNT" == "true" ]]
|
||||||
|
then
|
||||||
|
$MOUNT -o remount,ro "$MOUNT_DEVICE" "$SNAPSHOT_RW"
|
||||||
|
if (( $? ))
|
||||||
|
then
|
||||||
|
echo "snapshot: could not remount $SNAPSHOT_RW readonly"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Fin de backup de ${REMOTE_LOCATION} vers ${SNAPSHOT_RW}/${NAME}/ a $(date +"%H:%M, le %d/%m/%Y")"
|
||||||
|
echo '-----------------------------------------------------------------------'
|
||||||
|
}
|
||||||
|
|
||||||
|
rotateBackup() {
|
||||||
|
# rotating snapshots
|
||||||
if [ -f "$SNAPSHOT_RW/$NAME/daily.0" ]
|
if [ -f "$SNAPSHOT_RW/$NAME/daily.0" ]
|
||||||
then
|
then
|
||||||
echo "Previous backup failed, skipping rotation."
|
echo "Previous backup failed, skipping rotation."
|
||||||
@ -120,42 +146,56 @@ do
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
runBackup() {
|
||||||
# step 3: rsync from the system, linking to latest snapshot if files are
|
# step 3: rsync from the system, linking to latest snapshot if files are
|
||||||
# identical.
|
# identical.
|
||||||
RSYNC_OPTS="-a \
|
RSYNC_OPTS="-a \
|
||||||
--delete \
|
|
||||||
--delete-excluded \
|
|
||||||
--exclude-from=$EXCLUDES \
|
--exclude-from=$EXCLUDES \
|
||||||
--bwlimit=$BWLIMIT"
|
--bwlimit=$BWLIMIT"
|
||||||
|
|
||||||
if [ -d "$SNAPSHOT_RW/$NAME/daily.1/" ]
|
for((backup_num=0;backup_num <= MAX_ROTATE;backup_num++))
|
||||||
|
do
|
||||||
|
if [ -d "$SNAPSHOT_RW/$NAME/daily.$backup_num" ]
|
||||||
then
|
then
|
||||||
RSYNC_OPTS="$RSYNC_OPTS \
|
RSYNC_OPTS="$RSYNC_OPTS \
|
||||||
--link-dest=$SNAPSHOT_RW/$NAME/daily.1/"
|
--link-dest=$SNAPSHOT_RW/$NAME/daily.$backup_num"
|
||||||
fi
|
fi
|
||||||
|
done
|
||||||
|
for old_backup in "$SNAPSHOT_RW/$NAME/emerg".*
|
||||||
|
do
|
||||||
|
if [ -d "$old_backup" ]
|
||||||
|
then
|
||||||
|
RSYNC_OPTS="$RSYNC_OPTS \
|
||||||
|
--link-dest=$old_backup"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
$RSYNC \
|
$RSYNC \
|
||||||
$RSYNC_OPTS \
|
$RSYNC_OPTS \
|
||||||
"${REMOTE_LOCATION}" \
|
"${REMOTE_LOCATION}" \
|
||||||
"$SNAPSHOT_RW/$NAME/daily.0"
|
"$SNAPSHOT_RW/$NAME/$1"
|
||||||
|
|
||||||
# step 5: update the mtime of daily.0 to reflect the snapshot time
|
# step 5: update the mtime of daily.0 to reflect the snapshot time
|
||||||
$TOUCH "$SNAPSHOT_RW/$NAME/daily.0"
|
$TOUCH "$SNAPSHOT_RW/$NAME/$1"
|
||||||
|
|
||||||
# and thats it for home.
|
# and thats it
|
||||||
|
}
|
||||||
|
|
||||||
# now remount the RW snapshot mountpoint as readonly
|
# make sure we're running as root
|
||||||
if [[ "$REMOUNT" == "true" ]]
|
if [ ! $UID -eq 0 ]
|
||||||
then
|
then
|
||||||
$MOUNT -o remount,ro "$MOUNT_DEVICE" "$SNAPSHOT_RW"
|
echo "Sorry, must be root. Exiting..."
|
||||||
if (( $? ))
|
|
||||||
then
|
|
||||||
echo "snapshot: could not remount $SNAPSHOT_RW readonly"
|
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Fin de backup de ${REMOTE_LOCATION} vers ${SNAPSHOT_RW}/${NAME}/ a $(date)"
|
if [ -n "$EMERG" ]
|
||||||
echo '-----------------------------------------------------------------------'
|
then
|
||||||
done
|
doBackup /etc/remote-backup/"${EMERG//\//_}"/config emerg
|
||||||
|
else
|
||||||
|
for config in /etc/remote-backup/*/config
|
||||||
|
do
|
||||||
|
doBackup "$config"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user