Hallo,
I tried to find a solution to generate backups on the fly (without storing them local) on an ftp backup space. So I wrote this small script which is able to do that.
ATTENTION:
Do not use this script in productive environment or with an unstable FTP Server location (e.g. laggy cloud services). The script does not give a feedback on errors (there is only one stored on the FTP Server - so if its is broken there is no other backup)! Use at your own risk!
ATTENTION 2:
I switched to Syncovery CL for Linux so I am no longer supporting/maintaining this script. If you are using this script and want more (like incremental backups or SFTP/WebDav support) you my check out the new backup soltion I am using: click here.
Features:
- generates compressed .tar.gz archives on a ftp backups space during compression (no local space needed)
- wildcards for include and exclude paths
There are still some features missing so maybe one of you can help me to improve this script:
Encrypt the backups with password
Add SFTP support
Backup version history (delete only not needed backups from the ftp server)
detect errors and send an email if there is one or more errors
Version 1.0:
- TARNAME="imscp"
- FTPUSER=""
- FTPPASS=""
- FTPHOST=""
- FTPPATH=""
- LOCALBACKUP="/home/ /root/ /var/www/virtual/*/backups/ /etc/ /var/mail/ /var/www/imscp/gui/plugins/"
- EXCLUDEPATHS="/etc/apache2/*/access.log"
- echo -n "Removing old backup file lists..."
- rm /tmp/tar_$TARNAME.lst
- rm /tmp/tar_exclude_$TARNAME.lst
- echo "Done"
- echo -n "Getting list of ignored folders..."
- touch /tmp/tar_exclude_$TARNAME.lst
- find $EXCLUDEPATHS -type f -print > /tmp/tar_exclude_$TARNAME.lst
- echo "Done"
- echo -n "Getting all files to backup..."
- find $LOCALBACKUP -type f -print | grep -vf /tmp/tar_exclude_$TARNAME.lst > /tmp/tar_$TARNAME.lst
- echo "Done"
- echo "Start backup process in 10 seconds - to abort press CRTL+C"
- sleep 10
- echo "Deleting old backups on the FTP server..."
- ncftp -u $FTPUSER -p $FTPPASS $FTPHOST << EOF
- rm -rf $FTPPATH
- mkdir $FTPPATH
- exit
- EOF
- echo "Creating new backup on the fly"
- tar cfvj - -T /tmp/tar_$TARNAME.lst | ncftpput -m -c -u $FTPUSER -p $FTPPASS $FTPHOST $FTPPATH/$TARNAME.tar.bz2
- echo "Backup finished"
Display More