Copy (almost) entire filesystem with minimal effort

Solution 1:

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.