Simple linux FTP backup script

Written by MyComputerAid on Sunday, June 1, 2008 23:30 - 0 Comments

This is a quick and simple linux FTP backup script we use to run on clients servers that have small backups that need to be shipped off to a remote FTP server somewhere.  You can basically backup anything from here, Mysql, Apache config files, webserver files etc…

Requirments:
Shell access
ncftp
Vi or Pico/Nano editor
Cron

Step 1:
Log into your server as the user you want to run this script as (usually root).  You can then create a file somewhere on your server (I usually put the file in /etc/backup)

# cd /etc
# mkdir backup
# cd backup
# nano backup.sh

Step 2:
Cut and paste the script I have written into the file and then edit the parts required (it is spretty streight forward to understand but I will put comments on each line — the comments will start with a * so do not add these comments into your script).  After you have edited and save the file you must chmod the file 755 to make it executable

#!/bin/sh
HOST=’192.168.1.3′
* this can be an ip address or a hostname of the destination FTP server
USER=’ftpbackup’
* the username of the ftp server
PASSWD=’backup0012′
* the password on the ftp server
DATE=`/bin/date +%Y%m%d`
* no edits for DATE
TIME=`/bin/date +%H`
* No Edits for TIME
HOSTNAME=`/bin/hostname`
* No edits for HOSTNAME

mysqldump -c -B -uroot -pfoobar DB1 DB2 mysql > data.sql &&
* This is if you want to backup your mysql database, DB1 and DB2 represent databases within mysql you want yo backup -uroot -pfoobar (change this to your mysql username and password). if you are not backing up mysql then remove the above line.

tar zcvf $DATE.$TIME.$HOSTNAME.tar.gz ./data.sql /etc/ /var/www > /dev/null &&
* you can edit this line as you wish if you are not backing up mysql you can remove ./data.sql, you can add directories such as /etc and /var/www

ncftpput -u $USER -p $PASSWD $HOST /tobebackedup $DATE.$TIME.$HOSTNAME.tar.gz ;:
* nothing to edit here

The finished script:

#!/bin/sh
HOST=’192.168.1.3′
USER=’ftpbackup’
PASSWD=’backup0012′
DATE=`/bin/date +%Y%m%d`
TIME=`/bin/date +%H`
HOSTNAME=`/bin/hostname`

mysqldump -c -B -uroot -pfoobar DB1 DB2 mysql > data.sql &&
tar zcvf $DATE.$TIME.$HOSTNAME.tar.gz ./data.sql > /dev/null &&

ncftpput -u ftpbackup -p backup0012 $HOST /tobebackedup $DATE.$TIME.$HOSTNAME.tar.gz ;:

Running the script on a schedule (Crontab howto):
as the user that you want to run the backup script as type the following commands:

crontab -e
To run weekly on Sunday enter the line:
* * * * 6 /etc/backup/backup.sh

Article written by MyComputerAid.com

Related posts:

  1. Linux main databases
  2. What is the most popular Linux?
  3. Linux LAMP an overview
  4. Get control of your severs using Startup/Shutdown Script
  5. Configure ntbackup in Windows server
  6. Disable Windows Scripting Host WSH
  7. Howto use public route servers for BGP ping and traceroute
  8. Size Requirements for the Volume Shadow Copy Service
  9. SBS backup utility
  10. Configure ntbackup in XP



Comments are closed.

Join our mailing list

Receive computer support information.

E-mail:

User Panel

2003 server - Sep 30, 2008 22:34 - 0 Comments

instant messaging srv records

More In Computers & PC


Microsoft Outlook - Sep 15, 2008 22:21 - 0 Comments

Resetting the Language for the Folder Names inside the Mailbox

More In Computers & PC


Windows XP - Oct 10, 2008 23:38 - 0 Comments

Restore your computer to earlier version

More In Computers & PC