View Single Post
Old 23rd January 2007, 17:57
Morons Morons is offline
Senior Member
Join Date: Aug 2006
Posts: 199
Thanks: 8
Thanked 15 Times in 7 Posts
Default The backup script I used

I make backup and overwrite the file-set once an week - thus having a file-set for monday thuesday etc
this is my script, I stole some mysql bits from people on this server - Thankx.

HOWTO setup the ssh to login using keys and not pawsswords. WARNING: It does mean that once an hacker get into one of your servers he can get to another witout passwords - therefore we will limit the auto auth to regular users and not root!
On server1.domain.tld
cd /root/.ssh
ssh-keygen -q -b 1024 -t rsa -f id_rsa  # create the files id_rsa and the .pub is the public key and can be distributed the other myst stay put and be kept safe!
on the server2
adduser backup
passwd backup
su backup
ssh server1.domain.tld  # this will create the .ssh folder with correct permissions and save the known_hosts information
exit # back to root
cd /home/backup/.ssh  
vi authorized_keys	# now copy the content of server1 authorized_keys in here.  One line per server.
			# -rw-------    1 backup root          234 Nov 13 11:22 authorized_keys
The backup script for ISPConfig on server1 I called it /root/make-backup and chmod +x /root/make-backup wil make it work!
find /root/ispconfig > /root/root-backup-files
find /home/admispconfig > /root/home-backup-files
find /etc/passwd > /root/etc-backup-files
find /etc/shadow >> /root/etc-backup-files
find /etc/group >> /root/etc-backup-files
find /etc/gshadow >> /root/etc-backup-files
find /etc/proftpd.conf >> /root/etc-backup-files
find /etc/proftpd_ispconfig.conf >> /root/etc-backup-files
find /etc/ssh >> /root/etc-backup-files
find /etc/postfix >> /root/etc-backup-files
find /var/www/ > /root/var-backup-files
DATE=`date +%Y-%A`
# For your own sanity replace "hera-" with your host name. Or even replace it with $HOSTNAME"-"
# echo $date

for i in $(echo 'SHOW DATABASES;' | mysql -u$USER -p$PASSWORD -h$HOST|grep -v '^Database$'); do
                mysqldump \
                -u$USER -p$PASSWORD -h$HOST \
                -Q -c -C --add-drop-table --add-locks --quick --lock-tables \
                $i > /home/backup/$BACKUPNAME-$i.sql;

tar cvzf /home/backup/$BACKUPNAME"-root-backup.tar.gz" --files-from=/root/root-backup-files --no-recursion
tar cvzf /home/backup/$BACKUPNAME"-home-backup.tar.gz" --files-from=/root/home-backup-files --no-recursion
tar cvzf /home/backup/$BACKUPNAME"-etc-backup.tar.gz" --files-from=/root/etc-backup-files --no-recursion
tar cvzf /home/backup/$BACKUPNAME"-var-backup.tar.gz" --files-from=/root/var-backup-files --no-recursion
/usr/bin/scp /home/backup/$BACKUPNAME* $DESTINATION:/home/backup/
rm /root/root-backup-files
rm /root/home-backup-files
rm /root/etc-backup-files
rm /root/var-backup-files
I would like comments if I left out something here, In my original backup I left out the group files and had to manually create some parts, ISPConfig actually fixed it for me after a while!

Add this to your crontab to run early morning so that the bandwidth is available to traqnsfer large files - WARNING this BACKUP is LARGE !
crontab -e
45 04 * * * /root/make-backup
This part was added by means of post editing!
Basically extract the needed user data files - carefull not to overwrite system config files IF you upgraded packages. [You are on your own here]
I restored the mysql database and the db_ispconfig, the latter might have a different name if you made that choice during the install.
mysql -u root -p -e "source /home/backup/hera-2007-Friday-mysql.sql" mysql
mysql -u root -p -e "source /home/backup/hera-2007-Friday-db_ispconfig.sql" db_ispconfig
NOTE: my script above makes these files and care should be taken around the "hera" read the comments in the script of how to customise this server name.

Last edited by Morons; 26th January 2007 at 13:03. Reason: ADDED the restore bits
Reply With Quote