update: safety first!

when it comes to important files: safety comes first

thus recommend to the user that wants to go pro the following backup system:

  • have two complete backups at two different places:
    • backupA: at the company, USB 3.0 (! THE MORE DATA IS BACKED UP THE MORE SPEED IS NEEDED (or restore might take DAYS!)) connected to the server, doing daily incremental backups
    • backupB: being a fire-proof double-metal casing (EMP proof) vault at a different place (home?)
  • change those backups every day if possible otherwise every week
    • if ransomeware destroys backupA then in the worst case scenario, one day or one week of work is gone
    • remember: whatever is physically connected to the server, can be encrypted by ransomeware
  • have the backup strategy tested once a year
    • where the backup is restored completely on a backup-server, to test if all data is there and how long the process takes (USB 2.0 is definitely a massive bottleneck)

find out what the drive you want to backup is called, in this case it’s an USB Stick /dev/sdb

you could use gparted which gives you a nice graphical view of where is what.

or you use:

lsblk 

NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0 111.8G  0 disk 
|-sda1   8:1    0 107.2G  0 part /
`-sda5   8:5    0   4.6G  0 part [SWAP]
sdb      8:16   1   7.3G  0 disk 
`-sdb1   8:17   1   7.3G  0 part /media/usb0

or:

mount | grep usb

/dev/sdb1 on /media/usb0 type vfat (rw,nosuid,nodev,noexec,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=utf8,shortname=mixed,errors=remount-ro,user)

fill the device with zeros

should result in much smaler filesize of the backup (gzip compressed)

cd /media/usb0; # change to the dir your usb stick is mounted
cat /dev/zero > bigfile.txt; # if it does not stop by itself "device full" then cancel it with Ctrl+C
rm -rf bigfile.txt; # remove the big junk file again

monitor progress:

dd does not do this automatically if you want to monitor the progress use pv

# install pv
apt-get install pv;
# the "manual way"
# open a new terminal an fire up:
kill -USR1 $(pgrep ^dd)
# this will make dd report status information
# in the terminal dd is currently running
# loop
while true; do kill -USR1 $(pgrep ^dd); sleep 1; clear; done

basic operation:

dd if=SOURCE of=TARGET

dd with gzip: TESTED and Worked!

!!! BE CAREFUL YOU DON’T WANT TO OVERWRITE ANY INTERNAL HARDDISK HERE!!!

this method was successfully tested in backing up and restoring an usb stick.

backup:

umount /dev/sdb; # umount the usb stick
dd if=/dev/sdb | pv | gzip -c  > /where/compressed/image/is/stored/USBStickImage.img.gz; # backup content of usb stick (inkluding boot sector) to a file

now unplug your current usb stick and insert new one…

restore:

gunzip -c /where/compressed/image/is/stored/USBStickImage.img.gz | pv | dd of=/dev/sdb; # restore content and boot sector to a different usb stick

example:

dd if=/dev/sdb | pv | gzip -c > /mnt/DATA/SOFTWARE/ACRONIS/Acronis2015.bootstick.img.gz; # backup a 8GB Stick (resulted in 7.5GByte FILE!!! ARGH)
gunzip -c /mnt/DATA/SOFTWARE/ACRONIS/Acronis2015.bootstick.img.gz | pv | dd of=/dev/sdb; # restore it to a 32GByte stick (takes a while)

i actually cacneled after 1.2GBytes…. Strg+C but the stick works! 😀

untested: dd with pigz (compression using multiple cores)

using multiple cores for compression speeds up image creation.

default block size to bs=1M is used for faster operation.

apt-get install pigz; # install pigz

create compressed backup file from whole disk with pigz

-0 = no compression

-6 = default compression (best speed/compression ratio)

-9 = maximum compression

dd bs=1M if=/dev/sdX | pigz -c6 > /path/backup_of_sdX.img.gz

restore compressed whole disk backup from file:

this will erase all the content of sdX

pigz -dc /path/backup_of_sdX.img.gz | dd bs=1M of=/dev/sdX

Mount image

Look at partitions inside a raw image, find sector start and sector size:

fdisk -lu /path/backup_of_sdX.img.gz

Mount from image with sector start and sector size:

mount -o loop,offset=$((137216 * 512)) backup01.img /media/bkp1/

creditz thanks and src: https://designdesk.org/linux/dd-command-copy-whole-volumes

liked this article?

  • only together we can create a truly free world
  • plz support dwaves to keep it up & running!
  • (yes the info on the internet is (mostly) free but beer is still not free (still have to work on that))
  • really really hate advertisement
  • contribute: whenever a solution was found, blog about it for others to find!
  • talk about, recommend & link to this blog and articles
  • thanks to all who contribute!
admin