3

I use rackspace cloud sites and don't have accsess to SSH or RSYNC on their servers, but I do access to SSHFS.

I would like to be able to backup my cloud site to my local Ubuntu server, which has SSH, RSYNC etc.

So far, I'm thinking the best way to do this, is to mount the site on the local server using:

sshfs username@remoteserver.com:/path-to-site/ ~/Sites_Mounted/site-name/ -o reconnect,cache=no,compression=yes,ServerAliveInterval=15

Reconnect - so the connection will reconnect if it drops

Cache=no - because we want live backups not old cached files

Compression - to minimise bandwidth usage

ServerAliceInterval - as SSHFS drops out after a long time and crashes

I was then thinking about using a RSYNC command to copy the mounded sites files to a backup directory on the local server, then when the next backup is due 12hrs later, copy/RSYNC the backup dir to a new backup dir (with different name i.e. 2012-01-01-sitename) then using a RSYNC comand to copy only the changes on the remote server to the new backup dir that contains the old/previous backup.

My questions are, will this approch work? If so, what commands would i need to use and would it be posible to include all those in a single .sh script that I could run?

Or is there a simpler, more efficient or better way to do this.

(I think I can zip the entire site on the server and download that but this seem a bit resource heavy)

hozza
  • 137
  • 4
  • How much of the file will rsync have to read to decide that it has not changed? I'm fairly certain it is not satisfied with mtime? If so, it risks reading the entire data-set each time; is that OK? – Bittrance May 13 '12 at 22:16
  • It's not one file but hundreds of 1-100B files in hundreds of folders and sub-folders. – hozza May 14 '12 at 06:50
  • @Bittrance, unless you use `--checksum` rsync generally looks at must mtime and file size which it gets via a stat() call on each file. – Zoredache May 14 '12 at 22:05
  • My approche seem like it would work, I will reply an answer if i can get it working. REF: http://serverfault.com/questions/135618/is-it-possible-to-use-rsync-over-sftp-without-an-ssh-shell#comment115416_135649 – hozza May 17 '12 at 21:23
  • Done some digging and come across this: still inconclusive but gives me info on the subject. http://kangry.com/topics/viewcomment.php?index=18524 – hozza May 17 '12 at 21:35
  • Also found this a duplicate question. No answer there... http://serverfault.com/questions/348533/rsync-over-sshfs-hangs – hozza May 17 '12 at 21:44

1 Answers1

0

I've had to clone several cloud based servers, here's my approach:

Stop any running services that you can. If that's not an option, you'll need to do db dumps and backups separately (i.e. anything that uses mysql, redis, solr, etc.)

create a directory in the root i.e. /x

mount /dev/sda1 (or xvda1 or whatever your root system partition is) on /x (as you can have one device mounted to two different points at the same time.) The value here is that you won't get errors for the devices in /proc, etc. If you're using lvm, a snapshot works great for this too.

At this point, you have a few options. If your server has enough disk space, simply make a directory /y and do

tar -zcvf --exclude '/x/*' --exclude '/y/*' /y/root.tar.gz /x/

If you don't, then you can shoot it to another node via ssh:

tar -zcvf - /x/ |ssh -i /blah.pem user@someplace.net 'cat - > /tmp/root.tar.gz'

Either route you go, you can then download the tarball.

Last and probably easiest, but not ideal in my mind, is to simply rsync the /x/ directory to your local machine.

Whatever route you go, if you have large databases or kruft you don't need, you save time by excluding them from the tar process (simply copying a running db can cause the db copy to be corrupted.)

Stephan
  • 999
  • 7
  • 11