Solved

Backup with rsync and tar

Posted on 2010-11-19
8
1,021 Views
Last Modified: 2012-05-10
I'm running ubuntu servers. I'm using 'rsync' for backing up necessary directories(/usr /var /etc..) to  a remote location so that I can immediately come up with the new server in case of system failure. The following is the rsync command:

rsync -avP --exclude 'udev' --exclude 'fstab' /etc /usr /var /lib /home /bin /sbin 192.168.2.100:/mnt/rsyncmounts/

To save disk space and to easily take and extract rsyncmounts directory, I thought of using 'tar'.
To create the tar file of rsyncmounts directory on the remote machine I used the following command:
tar -cvzf ~/clone.tgz /mnt/rsyncmounts
When I checked extracting it on a virtual machine using the following command, it's extracting under the directory which the tar is created(under /mnt/rsyncmounts) even having it specified to extract under /:
tar -xvpzf ~/clone.tgz -C /

Any tips or tricks to make it extract under the root directory /?
0
Comment
Question by:Thyagaraj03
  • 3
  • 3
  • 2
8 Comments
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 250 total points
ID: 34171493
Try

tar -cvzf ~/clone.tgz /mnt/rsyncmounts -C "/mnt/rsyncmounts" .

Please nothe the dot ( . ) at the end!

wmp


 
0
 
LVL 68

Assisted Solution

by:woolmilkporc
woolmilkporc earned 250 total points
ID: 34171499
Sorry, copy and paste error!

tar -cvzf ~/clone.tgz -C "/mnt/rsyncmounts" .

0
 
LVL 7

Assisted Solution

by:Hatrix76
Hatrix76 earned 250 total points
ID: 34171631
woolmilkporc is right, altough he did not explain why.

If you do tar ... /mnt/rsyncmounts tar includes the mnt/rsyncmounts path to the packages. If you do -C "/mnt/rsyncmounts" .  what it does is it changes to this directory, and then backups up everything "." so now it will be extracted like the root filesystem.

best.
0
Connect further...control easier

With the ATEN CE624, you can now enjoy a high-quality visual experience powered by HDBaseT technology and the convenience of a single Cat6 cable to transmit uncompressed video with zero latency and multi-streaming for dual-view applications where remote access is required.

 
LVL 68

Expert Comment

by:woolmilkporc
ID: 34171668
<< ... altough he did not explain why <<

I'm sure that Thyagaraj03 is familiar with the "-C ..." concept because he uses it when extracting (see question).

wmp
0
 

Author Comment

by:Thyagaraj03
ID: 34171887
@woolmilkporc: Great help!. I thought, it would take lot of time and I would have to change all of plans but you simply put an end to this issue. Thanks.

@Hatrix76: Thanks a lot for your explanation. Don't tell woolmilk that my next request would have been what you have answered.


Expecting one more tip from you(both). Is it possible to directly create a tar file on the destination from rsync what I'm using(the one I posted) instead syncing to the directory(rsyncmounts). Like using rsync and tar on source with ssh/pipe  something which ends with tar creation of the synced directories at the destination. If not possible let's end this post here itself. Thanks a lot!
0
 
LVL 7

Expert Comment

by:Hatrix76
ID: 34171985
Well, what I use sometimes is something like this:

tar -cvzf - -C "/mnt/rsyncmounts" --exclude=<excludes> <directories you need> | ssh user@server "cat - > /path/to/tarfile.tgz"

this will create the tar and transfer whilst creating to the server.

Of course you will loose the benefit of the rsync which saves bandwith because it will only transfer the differences.

Now, if you do a rsync now, then compress it to tar file to save space, and if you delete the synced content after the compression, than you can use this approach as it will be nearly the same (depends on how you use rsync (without ssh directly to rsync server) it's normally faster than an ssh connection.

If you depend on rsync then there is no way of doing it in one step, at least none that I am aware of.

best,
Ray
0
 
LVL 7

Expert Comment

by:Hatrix76
ID: 34171995
Ah, i forgot:

the -f - tells tar to use stdout for output instead of a file, this get's piped into the ssh session, and cat - > file reads from stdin (-) and pipes what it receives into the redirected file.

if you need more help regarding the excludes, etc. just ask.
0
 

Author Comment

by:Thyagaraj03
ID: 34187568
Thanks a lot.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question