Pages

Showing posts with label gunzip. Show all posts
Showing posts with label gunzip. Show all posts

Wednesday, July 18, 2012

How to take backup and incremental backup using Linux shell script

How can I take back up of a directory and update the changes(Incremental backup) to it.


Step1: Suppose you want to take backup of /home directory. Use tar(Tape ARchive) command  to do this as below

cd /
tar cvfz home.tar.gz /home

The options used here are

c --For creating the archive
v --For verbose mode, so that you can see what files are archiving
f --To take back to a file called home.tar.gz insted of tap drive
z --To compress it with Gzip

Step2: Once the first backup is completed update only changes to the archive by using below script

#!/bin/bash
gunzip /home/tar.gz
tar uvf /home.tar /home/
gzip /home.tar

Save this file and exit

The options used here are
u --For updating the archive with only new and updated files only
v --For verbose mode, so that you can see what files are archiving
f --To take back to a file called home.tar.gz instead of tap drive


First the script will unzip the archive file then it will update the archive with new and updated files from /home directory. Then once again gzip is used to compress this. 

Note: We can not update tar archive when it is compressed so we first uncompressed then only we updated the archive file.

Step3: Enter the crontab for this script to run at 3 AM on every day.

00 3 * * * /bin/bash /path/to/script

For more information on CRONTAB configuration Click here and for issues here. Please subscribe to our RSS feed to get updates on shell scripting.