Debian – How To dd or cp Entire Disk On Debian Remote Machine To Local Machine

backupcpdddebianrsync

I have read this post – How to dd a remote disk using SSH on local machine and save to a local disk

However, the following code doesn't work:

"dd if=/dev/sda | gzip -1 -" | dd of=image.gz

As I do not have any /dev/sda directory. I'm assuming this is because I'm using Debian 7.0.

Any help to take a complete copy of my vps is highly appreciated.

Best Answer

The device name of a disk depends on what type of disk it is (more precisely, on what type of bus and controller the disk is connected to, and what driver handles them). /dev/sda is the typical name for the first disk in a PC (other names can be used depending on the driver, e.g. for some older types of disk controllers or some hardware RAID controllers). In a VPS, the disk is normally a virtual one, and the device name depends on the virtualization technology, e.g. /dev/vda or /dev/xvda. You can find the block device names on your system with df or lsblk.

But do not use this to make a backup from a live system! You are very likely to end up with an unreadable backup. If the disk content changes while you're making the backup, which is unavoidable on a live system (e.g. a log gets written somewhere), then your image will be inconsistent — a bit of the old state, a bit of the new state — and may not be recoverable.

The preferred way to make a backup is to make a snapshot, i.e. a view of the filesystem that's frozen and doesn't change even as the real system keeps changing. How to do that, and whether it is at all possible, depends on how your system is set up. Some filesystem types such as btrfs and zfs have a built-in snapshot ability. LVM also can make snapshots of a volume.

If you can't make a snapshot (or even if you can) make a file-level backup. A file-level backup from a system that changes will be inconsistent, but if you don't make “important” changes then the backup will be usable. For example, if you move files around, they may be omitted from the backup if they happen to be moved from a directory that the backup program has not traversed yet to one that it has already traversed. On the other hand, if a log file keeps growing, you'll have some intermediate version of that file, but you won't have a damaged filesystem image. If a file is deleted and another file is created, you may have none of those files, or either one, or both, but you won't have the directory entry of the old file pointing at some data in the new file.

You can use GNU tar (as root!) to back up a Linux system complete with important metadata.

ssh root@vps 'tar -cJf - --acls --selinux --one-file-system /' >vps.tar.xz
Related Question