Backup-Skript
Here as an example my backup-Skript. It will mount, if not already happened, the NAS and the backup disk and makes a backup of the NAS via rsync.
#! /bin/bash
# backup from nas to /backupdisk
# root directories on NAS must exist or
# the corresponding share will not be backuped
NASROOT=/auto/nas
BACKUPROOT=/backupdisk
# definitions for findNewDisk()
MASK="/dev/sd?"
TIMEOUT=60
# Waits for a new disk to be connected
# returns device path in $newDisk if success
# or times out after $TIMEOUT seconds
WaitNewDisk()
{
disks=($MASK)
newDisk=""
t=0
while [ $t -lt $TIMEOUT ]; do
x=($MASK)
for d in ${x[@]}; do
if [[ ! "${disks[@]}" =~ "$d" ]];
then
newDisk="$d"
return
fi
done
sleep 1
let t=t+1
done
}
#####################################################
RSYNCOPTS="-a -H -v --delete"
# Note: this will automount the nas disk
nasdirs=($NASROOT/*)
if ! grep -q "$NASROOT" /proc/mounts
then
echo "nas not mounted!"
exit
fi
if ! grep -q "$BACKUPROOT" /proc/mounts
then
# power on backup disk
relay 1 on
WaitNewDisk
if [[ "$newDisk" = "" ]];
then
echo backup disk failed to appear
relay 1 off
exit
fi
echo backup disk is $newDisk
# assuming ${newDisk}1 as target partition
mount ${newDisk}1 $BACKUPROOT
else
echo backup disk is already mounted
fi
# backup is done by separate rsyncs for each root folder
# the corresponding directory must already exist on the
# backup disk or it will be skipped!
# this allows to split the backup do several disks
# e.g. one for each directory
for d in ${nasdirs[@]}
do
d="$(basename $d)"
if [[ -d "$BACKUPROOT/$d" ]]
then
echo Syncing $d
rsync $RSYNCOPTS $NASROOT/$d/ $BACKUPROOT/$d
else
echo skipping $d - directory does not exist on destination
fi
done
umount /usbdisk && sync && hdparm -Y /dev/sdc
sync
sleep 1
# power off backup disk
relay 1 off
UUIDs
There is some confusion about UUIDs of the disks. So here a short summary:
UUID
This is the UUID of the file system of a partition.
PARTUUID
This UUID is unique for a partition of the disk.
PTUUID
This is the UUID of the partition table, so you can consider this as a UUID identifiing the disk itself. It is common for each of the partitions.