Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 07-04-2004, 09:45 AM   #1
Registered: May 2004
Distribution: Debian Stretch
Posts: 144

Rep: Reputation: 15
Tar for backups ? Proper syntax ?

Ok i have a Dell 8500 laptop running Fedora Core 2, i came from running Redhat 9. I finally got my wireless working and video card and starting to customize my desktop and do not want to loose all this work since i got this far.....phew. So talk to me about backing this up as i hear people using tar right ? I want to be able to back it all up and completely get it back in case i screw up the kernel since i plan on working on it next. So would tar be a good bet and what is the syntax ? Also if i screw Linux up beyond recognition can i just boot off the first cd and get to a prompt under recovery and tar my stuff back ? I did a search but people where just talking about mondo and backup up to cd....etc . .... did not seem to be what i wanted to do. I just want to back up to a file on the same hard drive.
Old 07-04-2004, 10:16 AM   #2
Senior Member
Registered: Nov 2002
Location: pikes peak
Distribution: Slackware, LFS
Posts: 2,577

Rep: Reputation: 48
Back up your Data by Tar'ing 

Tar is solely an archiving application. Tar by its self wont compress files. 

Now you ask? "then what is a .tar.gz" 

It is a tar file that has been compressed with a different compression utility. 
The .gz=gzip is the compression app use to compress it. 
Here is tar in its simplest form 


tar -cvf filename.tar /path/to/files

-c means create 
-f means filename (-f should always be last when you using syntax) 
-v Verbose will display all the files its puts in the tar and error you might 
have incurred You should see the filename.tar file in what ever directory you 
ran tar from.
If you want to make the tarball compressed 

then -z is the option you want to include in your syntax 


 tar -zvcf filename.tar.gz /path/to/files

Now when I make a tarball I like to keep all the path's from which the file is 
in. For this use the -P (absolute path) 


 tar -zPvcf filename.tar.gz /path/to/file 

When I extract it I will see a new directory called /path 
and under that I will see the "to" directory, and the "file" is under "to" 

If want to backup ALL your files in your home directory EXCEPT the temp 
directory. No problem. 


 tar -zPvcf myhomebackup.tar.gz --exclude /home/milkman/temp /home/milkman 

The --exclude will give you this option, just slip it in between the tar 
filename and the path your going to backup. This will exclude the whole temp 
directory. You say you just want to backup only 
single files from all around the drive. 
Make a file called locations (call it anything you like). In locations place the 
full path to each file you want to backup on a new line. Please make sure that 
you have the read rights to the files you are going to backup. 



Now with the -T option I can tell it to use the locations file. 


 tar -zPvcf backup.tar.gz -T locations

Now if you want to backup the whole drive. Then you will have to exclude lots of 
files like /var/log/* and /usr/local/named/* 
Using the -X option you can create an exclude file just like the locations file. 


 tar -zPvcf fullbackup.tar.gz -X /path/to/excludefile -T /path/to/locationsfile

Now a month has gone by and you need to update your myhomebackup.tar.gz with new 
or changed files. 
This requires a extra step ;) 
You have to uncompress it first but not untar it. 


 gunzip /path/to/myhomebackup.tar.gz

This will leave your myhomebackup.tar.gz mising the .gz. 
Now we can update your tarball with -u and then we are going to compress it 


 tar -Puvf myhomebackup.tar /home/milkman | gzip mybackup.tar

It will add the .gz for you. 

Tar has lots of Oddities! 
read the man pages to get a lits of all the options. 

I have included a little perl script that I made so I can run it as cron job 
evernight and get a full backup each time. It wouldn't be that hard to update 
the tarball but I just like full backups. Feel free to use it. 

If you want to extract the tarball that is compressed 


 tar -zxvf filename.tar.gz

-x extract 

If it is not compressed then 


 tar -xvf filename.tar


#Created by Milkman    
#Change These paths to fit your needs.
my $filename="/home/sysbkup/backup";
my $exclude="/home/milkman/exclude";
my $data="/home/milkman/locations";
my $tar="\.tar";
my $gz="\.gz";


     system ("tar -Pzcvf $file -X $exclude -T $data");

	Hope this helps!!
Old 07-04-2004, 10:31 AM   #3
Registered: May 2004
Distribution: Debian Stretch
Posts: 144

Original Poster
Rep: Reputation: 15
I am guessing this does not get the partitions of course and will not be bootable. I tried to "ghost" my drive and all seemed well and i popped in another empty drive and restored the image it started to go into GRUB and sat there and never booted. So is there an all-in-one solution that is going to back up the entire drive.
Old 07-04-2004, 11:36 AM   #4
Registered: Jun 2004
Location: India
Distribution: CLFS
Posts: 521

Rep: Reputation: 38
Use the mirrordir util for hard-drive mirroring.You can use it make an

exact copy of the folder heirarchy.Download it from

Select a partition where you will satore your disk image.Make sure it

is big enough to hold large data.Create a directory to mount the

directory on and mount it.You need root permissions.

#mkdir -p /mirror/home
#mount /dev/hda4 /mirror/home
In this e.g,i'm mounting the 4th partition on the first disk.You may

change this according to your preference.Change drive name

accordingly(hda2,hda3 etc.)You can check your partitions with the the

command : fdisk -l.

After you type in the mount command.Now you are ready to copy the

contents of your directory.Enter the command:#mirrordir /home

This causes the contents of the home directory to be copied to the

/mirror/dir directory.Be very careful while doing this coz if you

reverse the order then the entire home dir will get deleted.Thus you

have the backup of the /home directory.You can run the mirrordir again

to update the mirrored directory.If the /home partition should crash

then you can replace the disk using the mirrored copy by typing
#mirrordir /mirror/home /home.Or you can turn the mirrored partition

into the into the actual partition by editing the /etc/fstab file and

change the device name for /home so that it matches the mirrored

directory.Now unmount and remouint the /home partition(or reboot) and

the mirrored dir will be mounted to home.

To automate the process,create a script that mounts the

mirror partition,run the mirrordir command,and then unmount the

partition.Create a script named <mirror>.h and place it in the

/usr/local/bin dir.

# mMirror the /home partition to a second hard drive
/bin/mount /dev/hda4 /mirror/home
mirrordir /home /mirror/home
/bin/umount /mirror/home

Now invoke the cron command with the -e opt..Add a line similar to this

at the end of the list

0 * * * * /usr/local/sbin/
Save and exit the editor.

It's always good to backup crucial data onto more than one source.Cd's

are a very good option.First create an image of the CDFS as a file on

your system.Invoke the mkisofs command and pass it the name of the file

sys image file to create,followed by the dir to base it on.

#mkisofs -R -o /var/tmp/ /home/user

An ISo image is created in a file named in the /var/tmp dir.The
-R causes the Linux specific file permissions and file names to be

used.Burn this image onto a cd and voila!your data is now safe.

The tar command is usually used to backup onto magnetic tape drives.
Old 09-30-2004, 08:59 PM   #5
LQ Newbie
Registered: Oct 2003
Posts: 24

Rep: Reputation: 15
tar -zvcf filename.tar.gz /path/to/files
/path/to/files is dir that i want to compress or save at this dir ???
Old 10-01-2004, 10:29 AM   #6
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Centos 7.7 (?), Centos 8.1
Posts: 17,849

Rep: Reputation: 2584Reputation: 2584Reputation: 2584Reputation: 2584Reputation: 2584Reputation: 2584Reputation: 2584Reputation: 2584Reputation: 2584Reputation: 2584Reputation: 2584
I can recommend this tool: . Nice GUI interface and works a treat on IDE and or SCSI inc SCSI tapes.
Old 10-01-2004, 05:19 PM   #7
Registered: Apr 2004
Distribution: Debian
Posts: 185

Rep: Reputation: 30
Mondo Archive is a very nice tool to use. Check it out at
Old 10-01-2004, 05:42 PM   #8
Senior Member
Registered: Dec 2002
Location: Mosquitoville
Distribution: RH 6.2, Gen2, Knoppix,arch, bodhi, studio, suse, mint
Posts: 3,296

Rep: Reputation: 65
Originally posted by ayie
tar -zvcf filename.tar.gz /path/to/files
/path/to/files is dir that i want to compress or save at this dir ???
path to files is the path to files you wish to backup to the file filename.tar.gz

if you want to backup a whole partition to a big file, dd if=/dev/hda1 of=bigfile.dd
if you want it gzipped dd if=/dev/hda1 | gzip | dd of=bigfile.dd.gz
to restore gzip -cd bigfile.dd.gz > /dev/hda1 or gzip -cd bigfile.dd.gz | dd of=/dev/hda1
Old 02-21-2006, 05:18 PM   #9
Registered: Jul 2005
Distribution: LFS
Posts: 43

Rep: Reputation: 15

an other suggestion is partimage. A really good backup program: Open Source, stable, backup complete partitions ( including mbr, in case of backing first partition ), GUI, splitting of backupfiles, backing over network, compressing, inlcuded in several livecd's ( and therefore maybe called a all-in-one-solution ).

Sincerely, RoadRunner.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Using tar to make regular backups - pros and cons Donboy Linux - General 12 07-30-2004 07:40 PM
security for backups (tar command) wedgeworth Linux - Software 1 03-18-2004 11:00 AM
tar or cpio - Which is better for tape backups? Br. Nicholas Linux - Software 2 07-02-2003 04:06 PM
Large backups or Tar doesn't work jeanpba Linux - Hardware 1 10-04-2002 10:04 AM
Incremental tar backups Pepe Linux - General 5 03-18-2002 03:31 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:25 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration