Solved

Backup with rsync and tar

Posted on 2010-11-19
8
984 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
 
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now