Copy (almost) entire filesystem with minimal effort

2

1

A couple months ago I switched from VPS to dedicated server, however all this time I haven't found the time to actually go through all the files I might need again, copy them and shut down the VPS.

How can I copy the entire filesystem (except maybe for system files which I will not need anyway) without shutting the VPS down, preferably straight to a different online machine (dedicated server), with minimal effort?

I have root access to both machines over SSH, but am unable to access the physical hard drives.

Robus

Posted 2015-07-27T17:05:50.763

Reputation: 234

Answers

4

The filesystem itself most likely can't be copied online, as it is changing all the time.

You can copy the files, preserving just about everything about every file, inside the filesystem pretty easily, though. Try rsync from your dedicated server:

rsync -avzHXShPs --exclude sys/ --exclude dev/ --exclude proc/ root@VPS:/ /path/to/backup_folder/

, where VPS is the IP address of your VPS and /path/to/backup_folder/ is the destination folder on your dedicated server.

If your VPS has a different SSH port, you can do this:

rsync -avzHXShPs -e "ssh -p PORT" --exclude sys/ --exclude dev/ --exclude proc/ root@VPS:/ /path/to/backup_folder/

, where PORT is the custom port number.

If you want to transfer any changed files since the file transfer started, just run the same command again. If files were deleted from the VPS and you want the deleted files to be removed from the backup on your dedicated server, just add the --delete flag to the rsync line.


Explanation

rsync flags

  • -a means "archive", which contains most of the settings to make nearly exact copies of all the files in a specified folder (in your case, / on the VPS).
  • -v means "verbose". It'll show you detailed information about what's being copied over.
  • -z means "compress", which is useful when copying over the network, as the network speed is often slower than the drives, and you can get time savings by sending compressed data over the network.
  • -H means "hard links", which preserves hard links, if they matter to you.
  • -X means "extended attributes", which preserves extended attributes. This doesn't work on all filesystems, but rsync will proceed even if it has errors copying over the extended attributes.
  • -S means "sparse", which is very useful for speeding up the transfer of files that contain a bunch of binary zeroes.
  • -h means "human-readable", which outputs human-readable information during the transfer.
  • -s means "protect arguments", only useful if your source or destination arguments have spaces in the path.

I have a hotkey to type that rsync line because I copy data a lot, and it's convenient to have all those flags most of the time.

rsync excludes

  • --exclude sys/ excludes the sysfs mount at /sys. Without it, you might encounter some weirdness like infinite recursion or infinite-size files.
  • --exclude dev/ excludes the devtmpfs mount at /dev, which wouldn't be useful on your dedicated server (and can even be a security risk) since the devices are completely different on the two different servers.
  • --exclude proc/ excludes the proc mount at /proc. The system information in this folder only applies to the original server.

Deltik

Posted 2015-07-27T17:05:50.763

Reputation: 16 807

2/tmp may be excluded too. If this folder is used how it should be then it is useless to backup its content. (and it's probably a tmpfs anyway) – piernov – 2015-07-27T19:53:44.120