Tuesday, April 22, 2014

How to take system backup Using tar command in Ubuntu Linux




How to take system backup Using tar command in Ubuntu Linux


The following is an exemplary command of how to archive your system.
tar -cvpzf backup.tar.gz --exclude=/backup.tar.gz --one-file-system / 
To understand what is going on, we will dissect each part of the command.
  • tar - is the command that creates the archive. It is modified by each letter immediately following, each is explained bellow.
    • c - create a new backup archive.
    • v - verbose mode, tar will print what it's doing to the screen.
    • p - preserves the permissions of the files put in the archive for restoration later.
    • z - compress the backup file with 'gzip' to make it smaller.
    • f - specifies where to store the backup, backup.tar.gz is the filename used in this example. It will be stored in the current working directory, the one you set when you used the cd command.
  • --exclude=/example/path - The options following this model instruct tar what directories NOT to backup. We don't want to backup everything since some directories aren't very useful to include. The first exclusion rule directs tar not to back itself up, this is important to avoid errors during the operation.
  • --one-file-system - Do not include files on a different filesystem. If you want other filesystems, such as a /home partition, or external media mounted in /media backed up, you either need to back them up separately, or omit this flag. If you do omit this flag, you will need to add several more --exclude= arguments to avoid filesystems you do not want. These would be /proc, /sys, /mnt, /media, /run and /dev directories in root.


No comments: