pingaan
Posts: 27
Joined: Tue Jan 19, 2016 11:27 am

Using "dd" to backup.

Sun Mar 13, 2016 2:42 pm

Hi,

I'm trying to backup the system using dd but it keeps ending up with filling up the disk. What am I doing wrong? I thought it could have something to do with the mounted drives but unmounting them before starting the dd made no difference. The system takes about 4 GB and the sd card is a 32 GB card.
The command thst fails is:

Code: Select all

dd bs=4M if=/dev/mmcblk0 of=/home/pi/p2p_backup.img
Regards.

User avatar
alexeames
Forum Moderator
Forum Moderator
Posts: 2869
Joined: Sat Mar 03, 2012 11:57 am
Location: UK
Contact: Website

Re: Using "dd" to backup.

Sun Mar 13, 2016 2:49 pm

pingaan wrote:Hi,

I'm trying to backup the system using dd but it keeps ending up with filling up the disk. What am I doing wrong? I thought it could have something to do with the mounted drives but unmounting them before starting the dd made no difference. The system takes about 4 GB and the sd card is a 32 GB card.
The command thst fails is:

Code: Select all

dd bs=4M if=/dev/mmcblk0 of=/home/pi/p2p_backup.img
Regards.
Your command is trying to copy the entire SD card (including all the empty space) into a directory on the same SD card. That's never going to work. You'd be better off using a USB card reader or mass storage device :)
Alex Eames RasPi.TV, RasP.iO

fruitoftheloom
Posts: 21633
Joined: Tue Mar 25, 2014 12:40 pm
Location: Delightful Dorset

Re: Using "dd" to backup.

Sun Mar 13, 2016 4:01 pm

Retired disgracefully.....
......to a more gentile life !

pingaan
Posts: 27
Joined: Tue Jan 19, 2016 11:27 am

Re: Using "dd" to backup.

Sun Mar 13, 2016 7:40 pm

Oh.. That's odd! Why would that be useful to anyone? :-) Explains it all though, thanks!
I'll try to copy it onto a bigger drive then. Just a waste of space! -_- I couldn't sort out rsync, it kept giving me permission owner issues, which is why I'm going to have to stick with dd.
If this fails I'll look into the script, fruitoftheloom.

Thanks!

pingaan
Posts: 27
Joined: Tue Jan 19, 2016 11:27 am

Re: Using "dd" to backup.

Sun Mar 13, 2016 7:53 pm

Skip the resize to use the whole card via raspi-config would be a sollution too? Unused space is not empty space, right?

User avatar
Jednorozec
Posts: 809
Joined: Sun Nov 24, 2013 2:17 pm
Location: Deposit, NY

Re: Using "dd" to backup.

Sun Mar 13, 2016 8:04 pm

You'd be much better off with rsync. It would be worthwhile learning how to use it.
The most important leg of a three legged stool is the one that's missing.
It's called thinking. Why don't you try it sometime?

rayjoh
Posts: 27
Joined: Thu May 23, 2013 11:48 am

Re: Using "dd" to backup.

Sun Mar 13, 2016 8:36 pm

pingaan wrote:Skip the resize to use the whole card via raspi-config would be a sollution too? Unused space is not empty space, right?
Run the command

Code: Select all

sudo fdisk -l /dev/mmcblk0

Disk /dev/mmcblk0: 7,4 GiB, 7948206080 bytes, 15523840 sectors

Device         Boot   Start      End  Sectors  Size Id Type
/dev/mmcblk0p1         8192   131071   122880   60M  c W95 FAT32 (LBA)
/dev/mmcblk0p2       131072  3661823  3530752  1,7G 83 Linux
/dev/mmcblk0p3      3670016 15523839 11853824  5,7G 83 Linux
Check the first line "Disk /dev/mmcblk0: 7,4 GiB..." That is the size of my SD-card. I need a filesystem bigger than 7,4GiB to store 7,4 GiB. dd copies all the blocks in /dev/mmcblk0. It does not understand if the SD-card have unused blocks. There is a workaround with compression. Pipe output from dd to gzip.

Code: Select all

dd if=/dev/mmcblk0 | gzip -9 > /home/pi/p2p_backup.img.gz 
But it is not a good idea to do a dd-backup of a live filesystem where a lot of random writes is done during the backup.
-- Raymond

User avatar
bodge99
Posts: 20
Joined: Tue Mar 08, 2016 7:09 pm

Re: Using "dd" to backup.

Sun Mar 13, 2016 10:12 pm

Hi,

The other consideration with using dd to create an image is the time when you wish to restore any image... The target device must be at least the size of the original device.. If the target is just a couple of bytes smaller then the write will fail.

A useful alternative in this case is to mount partition(s) from the image directly.. Once the target device is partitioned & formatted you can then just copy the filesystem(s) contents across.. See viewtopic.php?f=29&t=139299 for an example of where I do just this.

Bodge99

HankB
Posts: 127
Joined: Fri Jan 01, 2016 2:45 pm

Re: Using "dd" to backup.

Mon Mar 14, 2016 1:47 am

pingaan wrote:Oh.. That's odd! Why would that be useful to anyone?
That's pretty much the command I use to backup a card image when the card is plugged into my PC. That makes a huge difference. And it's very convenient if I want to preserve the entire image. However if I wanted to back up my personal data (usually just ~/Documents) I use rsync.

pingaan
Posts: 27
Joined: Tue Jan 19, 2016 11:27 am

Re: Using "dd" to backup.

Fri Apr 01, 2016 10:04 pm

Looking on it again I do agree that rsync would be the preferable way to backup, however I've only done it locally. I'm trying to backup to a mounted cifs share and I keep ending up with the same error. Can't seem to google a proper answer! :<

Code: Select all

rsync: chown "path-to-backup-folder" failed: Permission denied (13)
I have set the chmod to 777 both in the samba conf and on the mounted drive itself, with a -R to make it happen to all subfolders as well, but still nothing...

Cheers.

rayjoh
Posts: 27
Joined: Thu May 23, 2013 11:48 am

Re: Using "dd" to backup.

Sat Apr 02, 2016 7:17 am

pingaan wrote:

Code: Select all

rsync: chown "path-to-backup-folder" failed: Permission denied (13)
The samba server does not give root access to the samba client or you do not mount the share as root.
The parameter "admin users = your_client_user_name" in smb.conf on the samba server might help.
-- Raymond

pingaan
Posts: 27
Joined: Tue Jan 19, 2016 11:27 am

Re: Using "dd" to backup.

Sat Apr 02, 2016 5:49 pm

Didn't change anything, still outputs (13).

pingaan
Posts: 27
Joined: Tue Jan 19, 2016 11:27 am

Re: Using "dd" to backup.

Sat Apr 02, 2016 5:51 pm

I might add that it doesn't fail on all files. It's like the first 30.

Edit: ...and just for this specific device. My other pi's seem to be OK. The one that fails is the one running OSMC.. ??

pingaan
Posts: 27
Joined: Tue Jan 19, 2016 11:27 am

Re: Using "dd" to backup.

Sat Apr 02, 2016 8:44 pm

Let's say I'd go with the original command just wih a different destination folder, would I be able to then "extract" the image onto a smaller SD card? I mean would all the files be copied onto the card and fail with the empty space afterwards?
What I'm trying to do now is copy a system from a 32 gb sdcard to a 8 gb sdcard...

Cheers.

Return to “General discussion”