I want to backup my whole system. I am wondering if the dd command is a good choice for that.

dd if=/dev/sda of=/dev/sdb

For example: /dev/sda is my system partition (partition is on a ssd if that information is important) and /dev/sdb is my external usb hdd. Is it possible to clone the whole system to a specific directory on my external hdd? Like this:

dd if=/dev/sda of=/dev/sdb/directory

I thought of the possibility to write my own backup-script, which makes a weekly backup of my system using the 'dd' command. Beyond that i want to encrypt my backup directory. What is a good choice for doing that? (I thought of EncFS for example).

  • 1
    Please keep one question per.. question. – landroni Feb 26 '14 at 15:38
  • If sda is in use while running dd, you risk copying 'dirty' filesystems to sdb. – Andrea Corbellini Feb 26 '14 at 18:11

Another Solution:

Try running crontab -e and add something like the below: (see here for details)

# some comments are here

# rsync archive every day at midnight change /dev/null to a file name if you want to see the logs
0 0 * * * rsync –avu /path/to/source ~/rsync/daily > /dev/null

# rsync every sunday at 4am change /dev/null to a file name if you want to see the logs
0 4 * * 0 rsync –avu ~/rsync/daily ~/rsync/weekly > /dev/null

# rsync every 1st of the month use gzip to use less space change /dev/null to a file name if you want to see the logs
0 0 1 * * tar -cvzf ~/rsync/monthly/monthly_$(date +%m%d%Y).tar.gz ~/rsync/daily/

And to encrypt the folders you could do something like:

tar -cvz /path/to/directory | openssl des3 -salt > name_of_encrypted.tar.gz

And to decrypt:

cat name_of_encrypted.tar.gz | openssl des3 -d -salt | tar -xvz new_name_of_directory
|improve this answer|||||
  • You need to drop the -f from tar or it expects /path/to/directory to be the name of the file to output/input to/from instead of stdout/stdin. – psusi Feb 26 '14 at 18:06

No, it is a terrible choice for that. dd is a dumb animal. It doesn't know anything about the filesystem, so it blindly copies every single sector, whether it is used or free space. This results in a very large backup image. You also can not restore it to an even slightly smaller drive, even if it had plenty of free space.

Tools like partimage and ghost4linux ( and the built in e2image gained this ability in 14.04 ) are at least smart enough to skip the unused space. Conventional backup tools like tar and dump are much better since they offer the flexibility of restoring to slightly smaller disks if need be, or restoring only a subset of files that you accidentally deleted. They can also do incremental backups of only the files you have changed instead of doing another full image of the entire drive each week. You also might want to look into rsnapshot which can give you weekly backups that are browsable by each week, without taking up the disk space of full separate copies.

If you want to encrypt the backup, you can just use gpg to encrypt the file. For example: tar cz / --one-file-system | gpg -c > /media/sdb/backup.tar.gz.gpg.

For more information see http://wiki.ubuntu.com/BackupYourSystem

|improve this answer|||||
  • thank you! your answer clarifies alot. I can't upvote your answer (not enough points yet) but still want to give you some credits :) – Ubuntix Feb 26 '14 at 23:00

You could do that, there are many ways, depends on what you prefer.

If you make a dd copy of your disk (sda itself is the complete disk, not a single partition) you can copy this to a file (not directory) on a backup disk. The advantage will be that you include your bootsector. Disadvantage, you have to unmount the partition in use, in practice meaning you have to boot from a different device. Also it is a time consuming copy since it will copy everything every time again.

More often used are backup tools which do a file copy, they can (must) be used while the partition is mounted and they will only copy the changed files on the next run. Disadvantage, you first have to make your system bootable before you can fully restore. Most commonly used for this is rsync, but there are many dedicated backup programs.

For encryption is Encfs a possibility, however I would not use that for encrypting a diskimage because corruption somewhere in the file might make your image non-decryptable. In fact, I would prefer to use a encrypted archive instead.

I just looked at a lot of encryption methods combined with backup in this post, maybe interesting for you.

|improve this answer|||||
  • thank you very much! your post helped me alot. Can't upvote it yet but i appreciate your help! – Ubuntix Feb 26 '14 at 23:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.