Click to See Complete Forum and Search --> : How do I backup a directory with Gzip or tar ?
Donovan
02-05-2001, 10:57 AM
What command should I type lets say to compress the directory /etc and all its files and sub directories into a compressed file ?
I want it to keep ALL permissions of all directories and files so If I need to restore it it will have the same permission.
Gzip ? Tar ? What should I type exactly to do this ?
Thanks,
Donovan
ph34r
02-05-2001, 11:14 AM
tar cf myetcbackup.tar /etc
gzip myetcbackup.tar
Although you may want to RTM on tar to be sure you are keeping the proper permissions, not de-referencing links, etc.
X_console
02-05-2001, 12:15 PM
You could do it with one command too:
tar cvzf myetcbackup.tar.gz /etc
Wouldn't you want to do...
tar cvzfp etc.tar.gz /etc
to preserve your permissions?
-blah
Donovan
02-05-2001, 05:57 PM
Ok, and how do I FORCE the file to overwrite a previous file ? What should I add to this last command ?
Thanks,
Donov
ndelo
02-05-2001, 11:04 PM
tar cvvfp mydir.tar mydir should work fine and overwrite any previously tarred files of the same name.
diskman
02-06-2001, 01:58 AM
Here is how we have been backing up our files at work for 25 years in SCO and now Linux..
Example at the bottom of message:
Grabs permissions, owners, inode status, chattr attribs.
# cd /dirtobackup
# find . -print | cpio -ov -O/todir/archive.cpio
(Ignore the Truncating Inode messages. Its simply smashing the inode information in the archive)
Done.
To EXTRACT the archive with the same dir layout/permissions/owners etc.
# mkdir /dir you want it in
# cd /dir
# cpio -iudmv -I/todir/archive.cpio
Done
To Compress the heck out of the archive use the following:
# cd /dirtobackup
# find . -print | cpio -ov | bzip2 > /todor/archive.cbz2
To EXTRACT the compressed archive use:
# mkdir /dir you want it in
# cd /dir
# cat /pathtoarchive/archive.cbz2 | bunzip2 | cpio -iudmv
Done.
Say I want to back my /home dir<>partition.. I do the following.
# mkdir /backups
# cd /home
# find . -print | cpio -ov | bzip2 > /backups/homedir.cbz2
Done.
Now my /home partition crashes and I purchase a new 30 Gig maxtor. Wanna put /home back in..
# fdisk /hd?
# mke2fs /hd?
# mount /dev/hd? /home
# cd /home
# cat /backups/homedir.cbz2 | bunzip2 | cpio -iudmv
Now my /home is completely restored and all set to go with permissions etc.
*NOTE*
This archive procedure is not smart enough to ignore the archive it's creating. So if you crate a backup of / and you archive is in /backups it will start archiving your archive in /backups! You need to use the -prune switch in cpio to ignore the contents of /proc /home /tmp /mnt /windows etc. Let me know if you need the -prune command as I have written a pretty slick backup script that will ignore the dirs you specify. We use this procedure for backing up our windoze and *nix boxes to our 33Gb VXA tape drive at work. Toms Root and Boot recovery disk has all the commands you need to restore this archive (cpio/bunzip/gzip/compress/find/fdisk/mke2fs etc.). I use this at home and burn my backups to a CD-RW so I can restore my Linux and Windoze states from CD.
Hope this helps. It's not really that complicated, it just sounds like it is. :)