Hi,
Hoping someone can help
I have written the following script to backup my /home folder to an external hard-drive using rdiff-backup and want to use it on other machines hence the variables.
Code:
#!/bin/bash
# This script backs up the directory $BACKUPROOTDIR of the
# localhost to themountpoint $BACKUPPATH on the server $SERVER using rdiff-backup.
# Incremental backups from the last $DURATIONTOKEEP days
# are retained.
# Change the following variables to suit your machine
BACKUPROOTDIR="/home" # root of filesystem to be backed up
DURATIONTOKEEP="60D" # use the character D, W, M, or Y, indicating days, weeks, months, or years respectively
BACKUPPATH="/media/WD/$HOSTNAME-backup/"
LOGFILE="/var/log/WD_home_backup.log"
EXCLUDEFILE="/home/ian/WDbackupexcludelist"
EXCLUDEEXPRESSION="/home/ian/WDbackupexcludeexp"
# Commence backup script
# Check that rdiff-backup is installed
dpkg -l rdiff-backup | grep ii
if [[ $? == 1 ]]; then
aptitude install rdiff-backup
fi
# Set date in logfile
echo 'Start backup for 'date'\nBacking up' $BACKUPROOTDIR' to '$BACKUPATH >> $LOGFILE
# Check backup directory exists
if [ -d $BACKUPPATH]
then
echo $BACKUPPATH' used at destination' >> $LOGFILE
else
echo $BACKUPPATH' is not mounted'
echo 'BACKUP FAILED' >> $LOGFILE
exit 1
fi
# List installed packages and write to backup destination
echo 'Writing install applications list to backup destination'
dpkg --get-selections | grep -v deinstall > $BACKUPPATH/installed packages.list
echo 'Installed applications written to installed packages.list' >> $LOGFILE
echo 'SUCCESS'
# Copy sources.lst and write to backup destination
echo 'Writing sources.list to backup destination'
cat /etc/apt/sources.list > $BACKUPPATH/sources.list
echo 'Sources.list written to installed souces.list' >> $LOGFILE
echo 'SUCCESS'
# Check exclude file exists and warn if not
if [-e $EXCLUDEFILE]
then
echo 'exclude file' $EXCLUDEFILE ' used'
echo 'files in' $EXCLUDEFILE ' omitted' >> $LOGFILE
else
echo 'exclude file does not exist, backing up everything in' $BACKUPROOTDIR
echo 'exclude file does not exist, backing up everything in' $BACKUPROOTDIR >> $LOGFILE
fi
# Check exclude expression file exists and warn if not
if [-e $EXCLUDEEXPRESSION]
then
echo 'exclude expression file' $EXCLUDEEXPRESSION ' used'
echo 'expressions in '$EXCLUDEEXPRESSION' omitted' >> $LOGFILE
else
echo 'exclude expression file does not exist, backing up all file types in' $BACKUPROOTDIR
echo 'exclude expression file does not exist, backing up all file types in' $BACKUPROOTDIR >> $LOGFILE
fi
cd $BACKUPROOTDIR
# Remove the expired incremental backups
echo 'Removing expired backups older than '$DURATIONTOKEEP
rdiff-backup --remove-older-than $DURATIONTOKEEP $BACKUPPATH
echo "SUCCESS"
# Write confirmation of purge expired incremental backups to logfile
echo 'Expired backups older than' $DURATIONTOKEEP ' removed.....SUCCESS' >> $LOGFILE
# Backup files and print stasticts to logfile
echo "Starting backup"
rdiff-backup --print-statistics --exclude-filelist $EXCLUDEFILE --exclude-regexp $EXCLUDEEXPRESSION $BACKUPROOTDIR $BACKUPPATH >> $LOGFILE
echo "Backup completed"
# Write confirmation of backup completion to logfile
echo "Backup 'date'.....SUCCESS\n----------" >> $LOGFILE
# Verify files
echo 'Verifying files'
rdiff-backup --verify $BACKUPPATH >> $LOGFILE
echo 'Verify complete'
However when I execute it I keep getting the error Command not found and $/r.
Have I got it all wrong.
I changed permission using
Code:
sudo chmod 700 backup.sh
and execute the script with
Bookmarks