View Single Post
  #1  
Old 18th March 2013, 13:49
almere almere is offline
ISPConfig Developer
 
Join Date: Nov 2012
Location: Netherlands, Rotterdam
Posts: 231
Thanks: 20
Thanked 39 Times in 34 Posts
Send a message via Skype™ to almere
Thumbs up Backup script ( no question, just script )

Hey guys.

I have made a backup script for my machines. Maybe you will like it

It's making a .gz file for each directory and puts all .gz files to *.tar archive. Than it will transfer the *.tar file to a FTP server.

I have 3 servers, each is something, like 1.5 TB. For each server it takes 1.5 hours to make full backup and transfer it. I also limited tar and gzip commands for 20% CPU usage, because it loaded my CPU for 99%

As security for my hosting is at first place, i backup almost everything. If you are not SOOOO paranoid, as i am, you should disable directories, like: root, sys, boot, lib, lib64, bin... etc.

Here it is:
Code:
#!/bin/sh
### System Setup ###
### backup directory for temp. file sotrage.
BACKUP=/backups/tempbackup

### FTP ###
### your FTP server
FTPD="/"
FTPU="user"
FTPP="password"
FTPS="host.name"

### Binaries ###
TAR="$(which tar)"
GZIP="$(which gzip)"
FTP="$(which ftp)"

## Today + hour in 24h format ###
NOW=$(date +%Y%m%d)


### Create tmp dir ###
mkdir $BACKUP/$NOW
### you can add or delete directories. They will be set to *.gz file

$TAR -cf $BACKUP/$NOW/home.tar /home
$TAR -cf $BACKUP/$NOW/var.tar /var
$TAR -cf $BACKUP/$NOW/etc.tar /etc
$TAR -cf $BACKUP/$NOW/root.tar /root
$TAR -cf $BACKUP/$NOW/boot.tar /boot
$TAR -cf $BACKUP/$NOW/opt.tar /opt
$TAR -cf $BACKUP/$NOW/usr.tar /usr
$TAR -cf $BACKUP/$NOW/sys.tar /sys
$TAR -cf $BACKUP/$NOW/sbin.tar /sbin
$TAR -cf $BACKUP/$NOW/lib.tar /lib
$TAR -cf $BACKUP/$NOW/lib64.tar /lib64
$TAR -cf $BACKUP/$NOW/bin.tar /bin

ARCHIVE=$BACKUP/server01-files-$NOW.tar.gz
ARCHIVED=$BACKUP/$NOW

$TAR -zcvf $ARCHIVE $ARCHIVED

### ftp ###
cd $BACKUP
DUMPFILE=server01-files-$NOW.tar.gz
$FTP -in $FTPS <<END_SCRIPT
quote USER $FTPU
quote PASS $FTPP
cd $FTPD
mput $DUMPFILE
bye
END_SCRIPT

### deleting temp files ###
rm -rf $ARCHIVED
rm -rf $DUMPFILE
echo "Backup finished and transferred"
exit
Have fun.

UPD: see the post below, for full and complete backup structure.

Last edited by almere; 19th March 2013 at 08:18. Reason: updated
Reply With Quote
Sponsored Links