I know there are quite some tools a round to do backups, but i was in the mood to write a bash script so here’s how i currently do backups
#!/bin/bash
ACTKW=`date +KW_%U_%A`
ACT=`date +%U`
DELKW=$[$ACT - 2]
if [ `ls -l /home/rsync/*${DELKW}*| wc -l` -gt 0 ]; then
echo “Deleting KW ${DELKW} backup files….”
rm -rf /home/rsync/KW_${DELKW}_*
fi
echo “Making actual Backup…”
echo “Making dir ${ACTKW}”
mkdir /home/rsync/${ACTKW}
if [ $? -eq 0 ]; then
echo “Syncing”
rsync -b -r <user>@<remotehost>:/var/customers/webs/ /home/rsync/${ACTKW}
fiecho “…done”
So what does this script do?
First of all, the design of an backup
- Backups are made to /home/rsync
- The script creates a new directory which name is based on KW_<number of calendar week>_<day>
What happens
- We compare the old backups on there calendar week with the actual. Than we erase all data which is older than 1 week.
- We create a new directory based on KW_<number of calendar week>_<day> for today this would be KW_16_Tuesday
- All data from the froxlor webspace directory on the remote server are rsynced to this new directory
In Addition to that: I do a mysqldump on the server
mysqldump –all-databases -c –single-transaction –master-data -p<dbpassword> > /var/customers/webs/db_backup”`date +%A%U`”.sql
via cronjob, so i have a backup of the database too.
