View Single Post
  #2  
Old 23rd January 2007, 16:57
Morons Morons is offline
Senior Member
 
Join Date: Aug 2006
Posts: 189
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
Code:
cd /root/.ssh
ssh-keygen -q -b 1024 -t rsa -f id_rsa  # create the files id_rsa and id_rsa.pub the .pub is the public key and can be distributed the other myst stay put and be kept safe!
on the server2
Code:
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!
Code:
#!/bin/bash
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"-"
BACKUPNAME="hera-"$DATE
# echo $date
# echo $BACKUPNAME
USER=root
PASSWORD=yourmysqlrootpassword
HOST=localhost
DESTINATION=server2.domain.tld

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;
done;

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 !
Code:
crontab -e
45 04 * * * /root/make-backup
-----------------------------------------------
This part was added by means of post editing!
-----------------------------------------------
Restore
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.
Code:
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 12:03. Reason: ADDED the restore bits
Reply With Quote