Gotcha, Grafcom,
Ik heb dit backupscript zelf in gebruik (met een kleine wijziging, waarover straks meer) Mijn script ziet er als volgt uit:
#!/bin/sh
##########################################################################
# RSYNC BACKUP SCRIPT
#
# -h = help
# -s = source of rsync backup (music, photo, web, ....) - No Spaces
# -e = Ext Drive destination of backup (USB1, USB2, SATA)
# -d = Destination Directory on External Drive from top level *share/(.....) - No Spaces
# -p = Backup Partition Type is EXT3
# -u = Update mode
# -l = log file
# -q = quiet
# -v = verbose
# -n = No Execute Rsync just check validity of other switches
##########################################################################
#***************************************************************
# Default Variables
#**************************************************************
VERSION="1.0 adapted by Wizjos"
#***************************************************************
# Functions
#***************************************************************
print_header()
{
echo ""
echo ""
echo "##############################################################################"
echo "# rsync_backup.sh - version $VERSION "
echo "##############################################################################"
echo ""
}
#***************************************************************
# Get Options from the command line
#***************************************************************
while getopts "s:d:e:l:phqvnu" options
do
case $options in
s ) opt_s=$OPTARG;;
d ) opt_d=$OPTARG;;
e ) opt_e=$OPTARG;;
l ) opt_l=$OPTARG;;
p ) EXT3_MODE="-go";;
u ) UPDATE_MODE="-u";;
h ) opt_h=1;;
n ) opt_n=1;;
v ) RSYNC_MODE="-v";;
q ) RSYNC_MODE="-q";;
? ) opt_h=1;;
esac
done
#***************************************************************
# Print Help
#***************************************************************
if [ $opt_h ]; then
print_header
echo "Usage: "
echo " "
echo " rsync_backup.sh -s <dir> -e <ext_drive> -d <dir> [-l <log>] [-q -h -v -n]"
echo " "
echo " -h = Help "
echo " "
echo " * List this help menu "
echo " "
echo " -s = Source of rsync backup "
echo " "
echo " * Directory in the / that should be backed up "
echo " * i.e. (/volume1/music, /volume1/photo, /volume1/web, ....) "
echo " * No Spaces, no trailing / "
echo " "
echo " -e = External drive destination for the backup "
echo " "
echo " * i.e. (USB1, USB2, SATA) "
echo " "
echo " -d = Destination directory on Exernal Drive for the backup "
echo " "
echo " * i.e. the path from top level [usb/sata]share directory "
echo " * No Spaces, no trailing / "
echo " "
echo " -p = Backup Partition Type is EXT3 "
echo " "
echo " * Uses the -g and the -o options for the rsync "
echo " to maintains group and owner on files. Do not use on FAT32 "
echo " "
echo " -l = Log file for output "
echo " "
echo " * If specified any output of the rsync will go to the log "
echo " file passed in "
echo " "
echo " -q = Quiet mode "
echo " "
echo " * Run rsync command with -q switch to supress all output "
echo " except errors "
echo " "
echo " -v = Verbose mode "
echo " "
echo " * Run rsync command with the -v switch to use verbose ouput "
echo " "
echo " -n = No Execute Mode "
echo " "
echo " * Dont Run rsync command just check validity of other switches "
echo " "
echo " -u = Update mode "
echo " "
echo " * This forces the script to skip files that already exist "
echo " in the destination "
echo " "
echo "----------------------------------------------------------------------------"
echo " "
echo " Examples: "
echo " "
echo " - Backup music to USB1 drive in the directory foo using verbose mode. "
echo " "
echo " % rsync_backup.sh -s music -e USB1 -d foo -v "
echo " "
echo " - Backup photo to SATA drive in the top directory to log backup.log "
echo " "
echo " % rsync_backup.sh -s photo -e SATA -d . -l backup.log "
echo " "
echo " - Backup web to USB2 drive in the 2008/jan directory using quiet mode "
echo " "
echo " % rsync_backup.sh -s web -e USB2 -d 2008/jan -q "
echo " "
echo "----------------------------------------------------------------------------"
exit 1
fi
#***************************************************************
# Get the source of the rsync from the command line -s
#
# - This should be the directory you wish to back up
# in the /volume1/ directory on the DS.
#
# i.e music, photo, web, ........
#***************************************************************
#--------------------------------------
# Check to see if -s was passed in
#--------------------------------------
if [ $opt_s ]; then
PASSED_SOURCE_DIR=$opt_s
else
print_header
echo "No source directory for the backup specified."
echo ""
echo " Use -s <src_dir> on the command line "
exit 1
fi
BACKUP_SOURCE_PREFIX="/volume1/"
#TO BACKUP BEYOND /VOLUME1/SUBDIR (E.G./VOLUME1 AS ROOT) USE: BACKUP_SOURCE_PREFIX="/"
#TO BACKUP FROM ROOT (/) USE:BACKUP_SOURCE_PREFIX=""
#BACKUP_SOURCE_DIR=$BACKUP_SOURCE_PREFIX$PASSED_SOURCE_DIR
#---------------------------------------------
# Check to see if specified source dir exists
#---------------------------------------------
if [ -e $BACKUP_SOURCE_DIR ]; then
echo ""
else
print_header
echo "The specified source directory for the backup: $BACKUP_SOURCE_DIR "
echo "does not exist. "
echo ""
echo "Please check the -s option and pass in a valid directory "
exit 1
fi
#******************************************************************
# Get the ext dest drive of the rsync from the command line -e
#
# This should be USB1 or USB2 or SATA
#
# Mounted by the DS as
# - /volumeUSB1/usbshare
# - /volumeUSB2/usbshare
# - /volumeSATA/satashare
#
#******************************************************************
#--------------------------------------
# Check to see if -e was passed in
#--------------------------------------
if [ $opt_e ]; then
PASSED_EXT_DRIVE=$opt_e
else
print_header
echo "No External Drive for the backup specified."
echo ""
echo " Use -e [USB1,USB2,SATA]"
exit 1
fi
#--------------------------------------------
# validate the destination Drive passed in
#--------------------------------------------
if [ $PASSED_EXT_DRIVE = "USB1" ] || [ $PASSED_EXT_DRIVE = "USB2" ]; then
BACKUP_DEST_DRIVE="/volume$PASSED_EXT_DRIVE/usbshare/"
elif [ $PASSED_EXT_DRIVE = "SATA" ]; then
BACKUP_DEST_DRIVE="/volume$PASSED_EXT_DRIVE/satashare/"
else
print_header
echo "Invalid External Backup Destination specified: $PASSED_EXT_DRIVE."
echo ""
echo " Use -d [USB1,USB2,SATA]"
exit 1
fi
#--------------------------------------------------
# Check to see if specified dest drive is mounted
#--------------------------------------------------
if [ -e $BACKUP_DEST_DRIVE ]; then
echo ""
else
print_header
echo "The specified external drive is not mounted: $BACKUP_DEST_DRIVE "
echo ""
echo "Please check the -d option and pass in a mounted external drive "
exit 1
fi
#***************************************************************
# Get the destination of the rsync from the command line -d
#
# - This should be the directory you wish to back up to go to
#
#***************************************************************
#--------------------------------------
# Check to see if -d was passed in
#--------------------------------------
if [ $opt_d ]; then
PASSED_DEST_DIR=$opt_d
else
print_header
echo "No destination directory for the backup specified."
echo ""
echo " Use -d <dest_dir> on the command line "
exit 1
fi
BACKUP_DEST_DIR=$BACKUP_DEST_DRIVE$PASSED_DEST_DIR
#---------------------------------------------
# Check to see if specified source dir exists
#---------------------------------------------
if [ -e $BACKUP_DEST_DIR ]; then
echo ""
else
print_header
echo "The specified destination directory for the backup: $BACKUP_DEST_DIR "
echo "does not exist. "
echo ""
echo "Please check the -d option and pass in a valid directory "
exit 1
fi
#-------------------------------------------------------
# Log Files for Backups
#
# If log file is specified redired standard out and
# standard error to the log file
#
# Will append log and not over write it
#
# > log 2>&1
#-------------------------------------------------------
#--------------------------------------
# Check to see if -l was passed in
#--------------------------------------
if [ $opt_l ]; then
PASSED_LOG_FILE=$opt_l
LOG_FILE=$BACKUP_DEST_DRIVE$PASSED_LOG_FILE
else
LOG_FILE="/dev/null"
fi
#---------------------------------------------
# Check to see if specified log dir exists
#---------------------------------------------
BASENAME=`dirname "$LOG_FILE"`
if [ -e $BASENAME ]; then
echo ""
else
print_header
echo "The specified log directory for the backup: $BASENAME "
echo "does not exist. "
echo ""
echo "Please check the -l option and pass in a valid directory "
exit 1
fi
#***************************************************************
# Execute the Rsync
#***************************************************************
echo $0 $* | tee -a $LOG_FILE
echo " " | tee -a $LOG_FILE
echo " " | tee -a $LOG_FILE
echo "######################################################################" | tee -a $LOG_FILE
echo "# rsync_backup.sh - version $VERSION " | tee -a $LOG_FILE
echo "######################################################################" | tee -a $LOG_FILE
echo "# " | tee -a $LOG_FILE
echo "# Starting the requested rsync backup " | tee -a $LOG_FILE
echo "# " | tee -a $LOG_FILE
echo "# -Command : rsync -rlptD --delete --exclude="@eaDir" $RSYNC_MODE $EXT3_MODE $UPDATE_MODE" | tee -a $LOG_FILE
echo "# -Backup Src : $BACKUP_SOURCE_DIR " | tee -a $LOG_FILE
echo "# -Backup Dest : $BACKUP_DEST_DIR" | tee -a $LOG_FILE
echo "# -Log File : $LOG_FILE" | tee -a $LOG_FILE
echo "# " | tee -a $LOG_FILE
echo "######################################################################" | tee -a $LOG_FILE
echo " " | tee -a $LOG_FILE
((echo " rsync start at: `date` " | tee -a $LOG_FILE) 3>&1 1>&2 2>&3 | tee -a $LOG_FILE) 3>&1 1>&2 2>&3
echo " " | tee -a $LOG_FILE
#--------------------------------------
# Check to see if -n was passed in
#--------------------------------------
if [ $opt_n ]; then
echo " ---------------------------------------------------- " | tee -a $LOG_FILE
echo " WARNING: NOT RUNNING RSYNC -n SWITCH WAS PASSED IN " | tee -a $LOG_FILE
echo " ---------------------------------------------------- " | tee -a $LOG_FILE
else
((rsync -rlptD --delete --exclude="@eaDir" $RSYNC_MODE $UPDATE_MODE $EXT3_MODE $BACKUP_SOURCE_DIR $BACKUP_DEST_DIR | tee -a $LOG_FILE) 3>&1 1>&2 2>&3 | tee -a $LOG_FILE) 3>&1 1>&2 2>&3
fi
echo " " | tee -a $LOG_FILE
((echo " rsync end at : `date` " | tee -a $LOG_FILE) 3>&1 1>&2 2>&3 | tee -a $LOG_FILE) 3>&1 1>&2 2>&3
Een beste lap
Wat heb ik hiermee gedaan?
Ik heb deze code opgeslagen in een bestand BackupSyno.sh op /volume1 (plaats is niet zo heel erg van belang...). Wel van belang is dat je er voor zorgt dat er geen ^M's aan het einde van de regel staan. Als je de tekst bv. via kladblok bewaart en vervolgens naar je Syno kopiƫert heb je hier last van... Je dient de tekst op te slaan in Unix formaat.
Vervolgens log ik via telnet/putty in op de Syno en geef het volgende commando:
sh padnaarbestand/BackupSyno.sh -s volume1 -d . -e USB1 -l backup.log -v -u
Wat gebeurt er dan?
BackupSyno wordt gestart met als parameters:
-s volume1 (bron van de backup is /volume1)
-d . (doel van de backup is de root van het backupmedium)
-e USB1 (doelschijf is de disk op USB1)
-l backup.log (zo gaat de logfile heten)
-v (laat zien wat er gebeurt)
-u (sla reeds bestaande bestanden in de doeldir over)
Ik schreef al dat ik wat gewijzigd had. Dat betreft het stuk code van regel 161 t/m 164 (
BACKUP_SOURCE_PREFIX="/volume1/"
#TO BACKUP BEYOND /VOLUME1/SUBDIR (E.G./VOLUME1 AS ROOT) USE: BACKUP_SOURCE_PREFIX="/"
#TO BACKUP FROM ROOT (/) USE:BACKUP_SOURCE_PREFIX=""
#BACKUP_SOURCE_DIR=$BACKUP_SOURCE_PREFIX$PASSED_SOURCE_DIR
)
In het script zoals dat in de Wiki staat is de BACKUP_SOURCE_PREFIX="/volume1/"...
Aangezien ik geheel volume1 wil backuppen en niet slechts een subdir van volume1 heb ik hier BACKUP_SOURCE_PREFIX="/" staan.
Als je de hele Syno wilt backuppen laat je de prefix leeg en geef je als -s op '/' (zonder de quotes...)
Wellicht behoeft de doeldir ook nog enige verduidelijking (-d .) Als je het script doorneemt zie je dat de backup weggeschreven wordt onder bv. USB1/usbshare. Door nu . als doeldir op te geven wordt mijn hele volume1 onder usbshare weggeschreven.
De log is te vinden in USB1/usbshare als backup.log
Het prettige aan deze manier van backuppen is dat na de eerste keer backuppen enkel de verschillen worden weggeschreven (optie -u). Backuppen duurt eindeloos lang de eerste keer (het gaat niet zo hard naar die usb-schijf), maar een volgende backup overschrijft enkel de toegevoegde/gewijzigde bestanden (en verwijdert de niet meer bestaande).
Succes!
Wizjos