Originally Posted by
djbushido
Can i create an event for (ana)chron to backup my data every day when i log in? Also, this should just be a differential backup.
Yes, but I'd rather setup a script that runs at boot to do the backup.
Originally Posted by
djbushido
Can i set this to backup to a separate partition on my drive?
That's simple just mount the separate partition into your local filesystem (I have used /backup on my machine) and sync into it.
What I do is to make incremental snapshot-style backups. That means I make hardlink copies of my backed up files so that I have for each backup a "full" backup copy.
backup.sh
Code:
#!/bin/bash
unset PATH
# USER VARIABLES
BACKUPDIR=/backup # Folder on the backup server
MYSQLUSER=root
MYSQLPWD=***************
MYSQLHOST=localhost
MYSQLBACKUPDIR=/mysql_backup
EXCLUDES=/backup/backup_exclude # File containing exludes
DAYS=90 # After how many days shall the backups be deleted?
# PATH VARIABLES
CP=/bin/cp;
MK=/bin/mkdir;
DATE=/bin/date;
RM=/bin/rm;
GREP=/bin/grep;
MYSQL=/usr/bin/mysql;
MYSQLDUMP=/usr/bin/mysqldump;
RSYNC=/usr/bin/rsync;
TOUCH=/bin/touch;
FIND=/usr/bin/find;
## ##
## -- DO NOT EDIT BELOW THIS HERE -- ##
## ##
# CREATING CURRENT DATE / TIME
$MK $BACKUPDIR/current
$MK $BACKUPDIR/old
NOW=`$DATE '+%Y-%m'-%d_%H:%M`
MKDIR=$BACKUPDIR/old/$NOW/
$MK $MKDIR
# CREATE MYSQL BACKUP
# Remove existing backup dir
$RM -Rf $MYSQLBACKUPDIR
# Create new backup dir
$MK $MYSQLBACKUPDIR
#Dump new files
for i in $(echo 'SHOW DATABASES;' | $MYSQL -u$MYSQLUSER -p$MYSQLPWD -h$MYSQLHOST|$GREP -v '^Database$'); do
$MYSQLDUMP \
-u$MYSQLUSER -p$MYSQLPWD -h$MYSQLHOST \
-Q -c -C --add-drop-table --add-locks --quick --lock-tables \
$i > $MYSQLBACKUPDIR/$i.sql;
done;
# RUN RSYNC INTO CURRENT
$RSYNC \
-avzp --delete --delete-excluded \
--exclude-from="$EXCLUDES" \
/ \
/$BACKUPDIR/current ;
# UPDATE THE MTIME TO REFELCT THE SNAPSHOT TIME
$TOUCH $BACKUPDIR/current
# MAKE HARDLINK COPY
$CP -al $BACKUPDIR/current/* $MKDIR
# REMOVE OLD BACKUPS
for file in "$( $FIND $BACKUPDIR/old/ -maxdepth 1 -type d -mtime +$DAYS )"
do
$RM -Rf $file
done
exit 0
It's very simple that script. First I define a few things (where I want to have backups to, how long I want to keep them, ....)
I also have mysql databases, so I need to back them up also - you probably can just skip that.
Then I also say what shall not be backed up:
backup_exclude
Code:
/backup/
/bin/
/boot/
/cdrom/
/dev/
/initrd/
/initrd.img
/ionitrd.img.old
/lib/
/lost+found/
/media/
/mnt/
/opt/
/proc/
/sbin/
/srv/
/sys/
/tmp/
/usr/
/var/backups/
/var/cache/
/var/crash/
/var/local/
/var/lock/
/var/log/
/var/opt/
/var/run/
/var/spool/
/var/tmp/
/vmlinuz
/vmlinuz.old
So basically you just need to create those two files, set path accordingly, setup what you want to backup, setup what you don't want to...
Then make the backup.sh script executable and run it by cron or anacron or make an init.d entry for it...
Bookmarks