Link to home
Start Free TrialLog in
Avatar of Thyagaraj03
Thyagaraj03

asked on

Backup with rsync and tar

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 /?
ASKER CERTIFIED SOLUTION
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
<< ... 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
Avatar of Thyagaraj03
Thyagaraj03

ASKER

@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!
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
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.
Thanks a lot.