4

I have a 1.4TiB drive which has Nextcloud & normal Mint 18.2 distro stuff on it. Now using 25% of capacity... and would like a backup of this. Am using dd to copy (very slow) but my question is will it attempt to copy the entire 1.4TiB or will it stop at the point where data is not present... Can it even tell the difference ?

It's VERY slow... I'm using pv to monitor progress and it says 15 hours.

Hmmm

Dave

11
  • destination partition is only 750GB... Sep 15, 2017 at 18:03
  • 2
    There's no "point where data is not present". Files aren't stored from the beginning onwards, filesystems scatter them for various reasons.
    – gronostaj
    Sep 15, 2017 at 21:02
  • 1
    dd is pretty slow on most devices if you don't use a more appropriate block size than the default 512 byte. For modern drives 8, 16 or 32 MiB should be fine. Sep 15, 2017 at 22:08
  • 1
    @DavidFoerster On most hardware, that's irrelevant. Reading and writing small blocks results in more CPU overhead, but often the I/O speeds are the bottleneck anyway. The OP is seeing 26MB/sec, which is most likely limited by storage speed. Going to bigger block sizes won't help him. And while we're on the subject, larger is not better, because you'll push data out of CPU cache. The optimum is probably closer to something like 128KiB.
    – marcelm
    Sep 15, 2017 at 22:38
  • 2
    @marcelm: That runs counter to all of my first-hand experiences and measurements. I only get about ~40 MB/s with 512 B block size as opposed to 100 MB with larger sizes. I seriously doubt that main memory access times are going to dominate I/O here. Sep 15, 2017 at 23:30

4 Answers 4

11

dd doesn't pay attention to "files", just disk blocks (if you specify if=/dev/sda), so it's going to try to copy all 1.4TiB to the 750GB partition. This will fail.

Use a file-oriented backup tool like rsync, burp, or duplicity to just backup files, and not free space.

5
  • If the unused portion of the disk is still full of nothing but zeros, you can pipe the dd through gzip to cut down the amount of space as though empty blocks had been skipped. Compressing disk images is usually a good idea anyway as there are often a lot of relatively empty bits.
    – Perkins
    Sep 15, 2017 at 21:53
  • @Perkins, deleted files are probably still going to be there, so they would also take up space in the gziped image. Also, if you later want to recover a few specific files, you'd have to gunzip the entire image before able to mount it and recover them. It still seems better to use file-oriented tools like rsync, as waltinator suggests.
    – JoL
    Sep 16, 2017 at 0:29
  • 1
    @JoL How much of the filesystem is unused and not zeros depends a lot on the usage and the device. And there are tools to zero out free space regardless. File-based backup does tend to be more efficient, but you need to also store metadata like partition layouts and FS UUIDs and/or be prepared to reinstall the bootloader on a restore. dd has the advantage that it's simple and makes a bare-metal recovery also simple. But it also makes compression a definite must.
    – Perkins
    Sep 16, 2017 at 0:58
  • @Perkins You're right in that the proper backup method depends on the usage one intends to give to the backup. I wasn't thinking of having a simple way of restoring a whole machine, bootloader and all. I was thinking more on the side of at some point wanting to restore only some of the files (of the types that would be found under $HOME). To me, the latter case is more useful, but of course YMMV.
    – JoL
    Sep 16, 2017 at 1:06
  • @JoL unfortunately, I have yet to find a non-proprietary solution that allows for both usecases that still works. Norton Ghost works, but is absurdly expensive, and Mondo Rescue is free, but doesn't seem to work reliably on modern systems.
    – Perkins
    Sep 16, 2017 at 1:21
2

Device oriented or partition oriented cloning or backup tool

There are alternative device oriented or partition oriented cloning or backup tools.

Speed

You have used dd which is a very basic tool, that clones, copies every byte.

Clonezilla is another device oriented or partition oriented cloning or backup tool. It can tell the difference between blocks, that contain file data and free blocks, and it clones/copies only blocks that contain file data plus the data that contain information about the partition table and metadata of the file system in each partition. This makes Clonezilla faster than dd, particularly when there is a lot of free space on the device.

Security

dd is notoriuosly dangerous and deserves the nickname 'Data Destroyer' becauses it does what you tell it to do without questions. If you tell it to delete the family pictures ..., and it is a minor typing error away.

Clonezilla has checkpoints, where you can double-check, that you will be writing to the correct target device (and not to the device (the main drive or an external drive), where you store valuable data).

Modes of operation

Clonezilla can either clone directly, or create a compressed image of a whole device. This image is a a directory with several files, where the big files are compressed. Clonezilla can restore from an image to a new device (drive) with the same size or bigger, so that you can get a working system with the same properties as the original system, a clone.

Clonezilla can also {clone/make a compressed image} of one or more partitions separately, but in this case there will be no complete image to restore a complete clone of the original system.

What to do in your particular case

I think that a Clonezilla image file will be small enough in your case to fit in the target drive, at least if the original source drive is far from full with already compressed data. So you can try to back up your data by creating an image file of the whole source drive.

In order to rely on the backup, you should get a third drive, of at least the same size as the original source drive, and try to restore from the image to this third drive. It should work as a replacement of the original drive.


If this is 'too much' for you, if it is enough to backup your personal data and maybe some of the settings in your computer, a file oriented backup according to @waltinator's answer will be better.

1

The problem with dd is that it WILL copy everything -- even sectors that contain nothing but binary zeros and are not allocated to any file. AND it is easy to get the parameters wrong -- earning it the moniker "disk destroyer".

May I suggest CloneZilla -- it's a bootable front end that sets up your backup/restore request and coordinates their execution. It is particularly good at backing up/restoring just one partition on a physical disk.

CloneZilla has three options as to which utility to use to do the actual backup -- one of which is dd, but it has faster and better options, too.

Jennifer

0

Making an image of the filesystem data, instead of doing a dumb block-by-block copy of the underlying block device, is called a "dump".

The inverse is called "restore". Those man pages for dump utilities mentions the restore program.

For incremental backups, something at the file level is usually much better, but dumpfs tools can often read faster. And since their output is a single stream, you can easily pipe it through a light-weight compressor like lz4 or lzop, or just gzip. It's also fast to write because it's a single stream, so doesn't require any seeking or meta-data ops on the destination.

It's also potentially faster to read the source, because it's aware of the FS layout and will read the file/directory data in approximately the order it appears on disk, only skipping over holes. Descending through the directories might result in an access pattern that's a lot slower, seeking all over the place if files in a directory aren't near each other on disk.


TL:DR: dump/restore is a good way to copy whole filesystems around when messing around with multiple disks. It's often fast.

Not the answer you're looking for? Browse other questions tagged .