1

I'm making a backup of Raspbian (I know, this isn't the Raspberry Pi SE, but it's a Linux question and it probably isn't just Raspbian that has this problem and BTW, the size of the drive is 128GB). The first backup is only 68GB after compression. Then, I deleted the first backup. The next backup is over 100GB in size! If I deleted the second backup and do another one, I run out of space when making a backup (since I use sudo dd if=/dev/mmcblk0 bs=1M | gzip – | dd of=~/Desktop/backup-23-may-2020.gz and since the unused space isn't all zeros, the compression is getting worse)

To my knowledge, deleting a file using rm just marks that file deleted, instead of zeroing out the file. I want to be able to completely zero out all the deleted files so when I back up the whole disk, the compression is better because all the unused space are zeros.

Will this command do that? (You will need to install pv (pipe viewer) if you want to try out this command by running sudo apt install pv)

dd if=/dev/zero | pv -s 100g -S | dd of=~/zeros.txt

EDIT 2: Forgot the =. Thanks @Hermann.

I don't want to blindly execute this command because I did compile OpenCV on here and I refuse to do that again.

EDIT: According to df -h I have 102G of memory.

pi@raspberrypi:~$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root       115G  7.9G  102G   8% /
devtmpfs        1.6G     0  1.6G   0% /dev
tmpfs           1.7G     0  1.7G   0% /dev/shm
tmpfs           1.7G   26M  1.7G   2% /run
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
...
7
  • 1
    It's possible but it'll likely waste a lot of write cycles on your SD card. Why not backup files instead of full raw image? – frostschutz May 23 '20 at 17:02
  • I compiled OpenCV on my Raspberry Pi. I refuse to go through that again. – Unsigned_Arduino May 23 '20 at 17:03
  • What does OpenCV have that's not in the file tree? – frostschutz May 23 '20 at 17:05
  • I've also edited rc.local (much to everyone's dislike of it) and installing and configuring Raspbian would take too much time than just backing up the raw image. (BTW, I do use gzip) – Unsigned_Arduino May 23 '20 at 17:09
  • And, you can burn the raw image directly to a disk and plug it back in to the Raspberry Pi and it "just works". – Unsigned_Arduino May 23 '20 at 17:13
0

Will this command do that?

It is missing the = after the if, but apart from that: Yes. I do not know whether it is the most efficient way to achieve it, but it will to the job.

Though I recommend a dd-only variant like this:

dd if=/dev/zero of=~/zeros.txt bs=16M status=progress

No need for pv.

For complete root file-system backups, I recommend an offline-backup with e2image: Power down the pi, move the card into a PC, do not mount the root partition. Instead, shrink it with resize2fs -M, create a copy with r2image -rap, then expand it again with resize2fs.

Using partclone is probably even better, but I have no first-hand experience with it.

2
  • Oops, forgot the =. Thanks. – Unsigned_Arduino May 23 '20 at 16:47
  • But I will say this, running it through pv is definitely slower than doing it directly. Already at 3.8GB. – Unsigned_Arduino May 23 '20 at 16:51

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.