How to create an image of a Live system over ssh?

19,850

Solution 1

It's not really possible under Linux. The reason it is under Windows is Volume Shadow Copy.

If your system uses LVM you can take a snapshot and then rsync that over for an atomic copy of the files, you would need to restore partitions/boot loader however.

Easiest method if it must be done, is use dd to copy it:

dd if=/dev/sda | ssh user@remotehost 'dd of=/path/to/output'

And then in order to make 100% sure your files are ok, rsync from the running one on to the drive you dd'd the image to once you've mounted it. (I've skipped rsyncing the differences hundreds of times with no ill effects, but that is only on heavily read based server access)

Solution 2

Use dump(8) to create a snapshot of the (file)system.

dump -0aLf /path/to/dumpfile /

That will create a live dump of the root-filesystem and save it to /path/to/dumpfile. That dump can be transferred over ssh to another computer. Or you can do it in one go by the use of this.

dump -0aLf - | ssh my.backup.server dd of=/path/on/my/server/dumpfile

That can later be restored by the following:

cd /where/I/should/restore
restore -xf /path/to/dumpfile

Applications such as databases will have to be handled separately. With a MySQL database for instance you have mysqldump to create a textfile of sql commands that can be run on another MySQL server in order to be imported there. Other databases have similar methods.

Solution 3

if there is only a root-fs to copy simply on your target machine use something like:

rsync --numeric-ids --delete -vax source_machine:/ /target_dir

twice or more often. The second run already reuses cached entries from the first run, goes very fast and gives almost a real snapshot with some restrictions. You can watch the 'atomicness' by simply repeating the 'rsync' an arbitrary amount of times. There mostly are very few files (logfiles and such) that really changed between the iterations (and thus need to be copied/deleted).

Share:
19,850

Related videos on Youtube

rfverbruggen
Author by

rfverbruggen

Updated on September 18, 2022

Comments

  • rfverbruggen
    rfverbruggen over 1 year

    I have a question about a FreeBSD server that I cannot access at the moment. But because we would like to try some new stuff we want to create a backup of this system first.

    The question is: is there any possibility to create a disk image over ssh from the whole server disk that is currently a live system?

    If there is: I would like to know how to do this.

  • artscan
    artscan about 7 years
    Second dump command doesn't include destination.
  • fuzzyTew
    fuzzyTew about 3 years
    There are many, many ways to do this ... you just listed one. you could even throw a compression algorithm in that pipe.