Linux simple backup with FTP

Linux simple backup with FTP

This is my first post under new domain ‘’. I’m planning to blog more from now on as I have loads of new things to blog about :).
Today I will present you with simple backup shell script I have running on one of my servers. The script is damn easy and all it does is:

  1. remove any earlier backup dirs and create new empty one
  2. create mysql dump for the applications you want to backup
  3. create tar.gz of the entire home directory
  4. create tar.gz of the apache director to preserve settings
  5. create tar.gz of everything I’ve created earlier to place everything in a single file
  6. ftp the file to a backup server

Lets start with the first task. Removing and creating dirs is pretty simple:

rm -Rf /root/temp_bckp
mkdir /root/temp_bckp

Creating mysql backup we can do the easiest using mysqldump utility. The command for this is:

mysqldump --user=your_db_user your_db_name > /root/temp_bckp/your_Db_name.sql --password=your_db_password
echo 'sql dump finished'

Once we got all dumps in place we can start compressing home and apache directories directory:

tar -zcvf /root/temp_bckp/home_bckp.tar.gz /home
echo 'tar of home finished'

tar -zcvf /root/temp_bckp/etcapache.tar.gz /etc/apache2/
echo 'tar of etc/apache finished'

Somwhere at the top of the script we store current date as a variable and we use it to name the final backup archive:

DATEX=`date +%d%m%y`

Final backup archive:

tar -zcvf /root/temp_bckp_$DATKA.tar.gz /root/temp_bckp
echo 'tar of all finished'

When we have all zipped together we are ready to send it over to the ftp backup server, I use ncftp utility which you can easily get on debian based distros using apt-get install ncftp or aptitude install ncftp.

ncftpput -u ftp_user -p ftp_password . temp_bckp_$DATKA.tar.gz
echo 'ftp finished'

For ftp server I personally use Linode services which are very cheap in the basic package, you can check their offers here

Complete shell script you can download from storage43 under this link
Happy backuping 😉

Leave a Reply