?
Solved

Backup with rsync and tar

Posted on 2010-11-19
8
Medium Priority
?
1,056 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
Congratulations! You’re Certified – Now What?

Starting a new career can be overwhelming. Becoming certified in your field of expertise is a great start, but where do you go from here?  Here are some tips to help you on your career journey.

 
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

Are You Using the Best Web Development Editor?

The worlds of web hosting and web development are constantly evolving. Every year we see design trends change, coding standards adapt and new frameworks/CMS created. With such a quick pace of change it’s easy to get lost trying to keep up.

See if your editor made the list.

Question has a verified solution.

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

Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
The purpose of this article is to show how we can create Linux Mint virtual machine using Oracle Virtual Box. To install Linux Mint we have to download the ISO file from its website i.e. http://www.linuxmint.com. Once you open the link you will see …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Suggested Courses
Course of the Month7 days, 23 hours left to enroll

765 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