Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Backup with rsync and tar

Posted on 2010-11-19
8
Medium Priority
?
1,071 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 1000 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 1000 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 1000 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

In my business, I use the LTS (Long Term Support) versions of Linux. My workstations do real work, and so I rarely have the patience to deal with silly problems caused by an upgraded kernel that had experimental software on it to begin with from a r…
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…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Suggested Courses

610 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