by madeye » Apr 24th, '14, 23:07
I would suggest using rsync to do that. But it depends on what you are comfortable with. Me I like the console

Below I have listed the script I use to do my backup. But of course there exists alot of other options like e.g. storebackup (
http://savannah.nongnu.org/projects/storebackup)
- Code: Select all
#!/bin/bash
###############################################################################
#
# Script to make a backup of files using rsync.
# It rotates directories automatically.
#
# To ensure the backupdrive is mounted, the script checks for the existance of a file named
# 'mount_OK' (without the quotes)
#
# Created 2014 by Rene Rasmussen
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301, USA.
#
###############################################################################
# Backup drive mountpoint
backup_drive="/mnt/backer"
# Parent backup directory
backup_parent_dir="${backup_drive}/homeback"
# Number of backups
# (number of directories in rotation)
# count starts from 0, so below value defines directories+1
backup_dir_count=12
#initialize errors variable
errors=0
# Check if drive is mounted
# (check for mount_OK file)
okFile=${backup_drive}/mount_OK
if [ -f $okFile ]
then
# If the destination folder does not exist, it will be created
if [ ! -d $backup_parent_dir ]
then
mkdir -p $backup_parent_dir
chmod 750 $backup_parent_dir
fi
# Rotate backup directories
for (( c=$backup_dir_count; c>=2; c-- ))
do
if [ $c -eq $backup_dir_count ]
then
dirPath=${backup_parent_dir}/backup$c
#echo "0 = $dirPath" #debug
if [ -d $dirPath ]
then
rm -rf $dirPath
fi
fi
dirPath1=${backup_parent_dir}/backup$((c-1))
dirPath2=${backup_parent_dir}/backup$c
#echo "1 = $dirPath1" #debug
#echo "2 = $dirPath2" #debug
if [ -d $dirPath1 ]
then
mv $dirPath1 $dirPath2
fi
done
# copy contents from backup0 to backup1 with hardlinks
dirPath1=${backup_parent_dir}/backup0
dirPath2=${backup_parent_dir}/backup1
if [ -d $dirPath1 ]
then
cp -al $dirPath1 $dirPath2
fi
# remove old datestamp file from rsync destination
if test -n "$(find $dirPath1 -maxdepth 1 -name 'MyBackup*' -print -quit)"
then
rm $dirPath1/MyBackup*
fi
# sync files to backupfolder
rsync -aq --delete /home $dirPath1
# create datestamp (empty) file
touch $dirPath1/"MyBackup from $(date '+%A, %d %B %Y, %T')"
else
errors=1
fi
# Error handling
if [ $errors != 0 ]
then
# Select error message based on errors value
# errors = 1 => Backup drive not mounted
fdesc="ERROR with database backup"
case $errors in
1)
fbody="Backup location not accessible! Please investigate cause!"
;;
*)
fbody="Something went wrong. Please investigate!"
;;
esac
# Error message for screen
echo $fdesc
echo $fbody
## error email for admin
receiver="admin@example.com"
echo $fbody | mail -s "$fdesc" $receiver
exit
fi
## rsync options
# The option -n can be used to make a dry-run
# The option -P shows the progress
## Description of option switches
# Option -C => CVS exclude
# Option -v => Verbose
# Option -r => Rercursive
# Option -t => Times
# Option -p => Permissions
# An alternative to the above options is option -a
# Option -a => -rlptgoD
# Option -r => Rercursive
# Option -l => links
# Option -p => Permissions
# Option -t => Times
# Option -g => Group
# Option -o => Owner
# Option -D => devices & specials
Just add a cron job for it, and of it goes at the time you specify

- Madeye
When I supply commands in an answer, please make sure you understand them before you run them! Use google or man to check!