Saturday, April 30, 2011

BACKUP



                                 BackUp

Command “tar” : It converts multiple files in a single file. [ file's extension is .tar ]

Options : We can check the options of this command by typing
# man tar
the main options are as follows :

a) -c : To create a back up.
b) -x : To restore back up.
c)-A : To concatenate. i.e. to add one tar file in another tar file.
d)-d : To compare the backup and the original directory whose backup is taken.
e)- -delete : To delete a file from tar file.
f)-r : To append a file at the end of tar file.
g)-t : To see contents of tar file.
h)-u : To update. Only new files in added to the tar file.

To check how commands work just create a “/backup” directory.
To take Back Up : run the below command,
# tar -cf /backup/backup1.tar /p1

Here, the back up of “/p1” directory is taken in file backup1.tar and stored at    “/backup” folder.

Now to see contents of “backup1.tar” file give command,
# tar -tf /backup/backup1.tar

Create new files in /p1 : To update backup, give command
# tar -uf /backup/backup1.tar /p1

Here only new files from /p1 are added to backup1.tar file.
To check new contents of tar file give same command,
# tar -tf /backup/backup1.tar

Now Take backup of another directory :
# tar -cf   /backup/backup2.tar    /abc

Now we add backup2.tar to backup1.tar :
# tar -Af /backup/backup1.tar /backup/backup2.tar

To see the contents :
# tar -tf /backup/backup1.tar

To Restore Backup : Give command,
# tar -xvf /backup/backup1.tar

If you don't want certain directories backup say “temp” then you can give command like,
# tar -cf /backup/newbackup.tar /p1 --exclude temp
where “temp” Is within “p1”.

If you don't want backup of certain files in a directory then just mention the names of these files in a new file and give path of that new file.
i.e. if we don't want files a1, a2, a3 then add these names in a new file say “abc”
# vim abc
a1 a2 a3
# tar -cf /backup/newbackup.tar /p1 -X abc

To convert backup in “.zip” format :
# tar -cvzf /backup/backup3.tar.gz /p1

To extract this backup :
# tar -xvzf /backup/backup3.tar.gz






No comments:

Post a Comment