How-to: Local Backup with rsync

A backup using the rsync command can be very useful because it:

Takes less time to replicate

rsync will replicate the whole content between the source and the destination directory only once. Consecutive rsync’s will transfer only the changed blocks or bytes, which makes it very fast

uses Less bandwidth usage

rsync will use compression of data block by block at the sending end and decompress at the receiving end

is Secure

rsync uses ssh protocol during transfers and hence allows encryption of data.

The script broken down

I will create a script which will backup my current web directory /data to the same server on a disk mounted at /backup. The script if broken down, can be viewed as:

rsync -azvu –progress /data/ /backup

wher options

  • z is for compress mode
  • v is for verbose mode
  • a is to preserve symbolic links, permissions, timestamp and to be recursive
  • u is to preserve unmodified files at the destination
  • progress is to show the progress during transfer

An extract of the transfer start is:

sending incremental file list
8713 100%    0.00kB/s    0:00:00 (xfer#1, to-check=1004/1010)

ending with:

sent 284122142 bytes  received 230478 bytes  1914832.46 bytes/sec
total size is 379003084  speedup is 1.33

Now, if I perform a second transfer, the result at the end will be much faster. Here’s a extract of that transfer:

[root@sdb backup]# rsync -avzu –progress /data /backup
sending incremental file list

sent 278200 bytes  received 1778 bytes  50905.09 bytes/sec
total size is 379003084  speedup is 1353.69

 The script

Let’s convert that into a nice and clean script, shall we?

Create a file in

vi /scripts/

Paste the following:


# declare variables



#rsync command, make sure the user you run this file as has the required permissions to the source/dest folder

#we dont need progress or verbose, this runs in background mode


Chmod 777 the sh file

chmod 777 /scripts/

Test the file

sh /scripts/

[root@sdb ~]# sh /scripts/
sending incremental file list

sent 278200 bytes  received 1778 bytes  62217.33 bytes/sec
total size is 379003084  speedup is 1353.69

Add it to crontab,

 crontab -e

Add this line at the end to run it daily, every 2AM

*    2    *    *    *    sh /scripts/


Read More

Offline Backup: Oracle Application Server 10g

This post is a follow up on the Stop & Start script I made for Oracle Application Server 10g.

You will need to create a new bash script which would basically have the following lines and should be placed in /home/oracle/scripts/


time_start=`date +%s`

source /home/oracle/scripts/oas/settings.conf


su – oracle -c “cd /home/oracle/scripts/;./”

#Create Backup on this Machine in /backup/daily.tar

tar cvf – /backup/daily.tar /u01″



su – oracle -c “cd /home/oracle/scripts/;./”

time_end=`date +%s`

time_exec=`expr $(( $time_end – $time_start ))`

echo “Application Server Backup Execution time is $time_exec seconds”

To make the backup script better, put that in a crontab by issuing, crontab -e and adding the line 21 30 * * * /home/oracle/scripts/

DO NOT FORGET TO CHMOD 777 those script files

Read More

Backup/Restore MySQL Database Linux

Initiating a backup from phpMyAdmin is not always the best solution when are you running a medium to massive web database. If you are running your mysql server on a vps or a dedicated server on Linux, those commands will definitely be useful to you.


mkdir -p /backup

cd /backup

mysqldump -u root -p database_name > database_name.dmp


cd /backup

mysql -u root -p database_name < database_name.dmp

Read More

Beginner: Full Linux Server Backup

This has been tested with a working server of Debian5.

Login as root

Make a backup directory. It is best if you have the backup directory on another partition or another hard disk

mkdir -p /backup

Create a backup sh file with arguments to backup the whole system while excluding contents of proc sys dev and backup directory

vi /backup/

tar -cvpf /backup/fullbackup.tar –directory=/ –exclude=proc –exclude=sys –exclude=dev/pts –exclude=backup .

Create a restore sh file which moves the fullbackup.tar file to / and then extracts it

vi /backup/

mv /backup/fullbackup.tar /fullbackup.tar

tar -xvpf /fullbackup.tar

Change the file permissions to make it executable

chmod -R 750 /backup

Add an argument to crontab to make it run at 22:10 daily.

crontab -e

10 22 * * * /backup/


To restore this backup, install a minimal version of the same linux flavor and then run /backup/

Read More