User avatar
Un4Seen
Posts: 330
Joined: Wed Oct 31, 2012 8:43 am
Location: Cluj-Napoca, Romania
Contact: Website

Backing up the SD card when Win32DiskImager fails

Fri Dec 26, 2014 7:14 am

Hello Everybody!

I have a Pi which has been running for over 2 years now from the same SD card. I'm periodically backing the data up under Windows (7) using Win32DiskImager. Unfortunately I've made some important changes to the Pi since the last backup and I am unable to back it up with Win32DiskImager any more, because it fails with read error at 88%. I've tried it several times, using several USB ports and the same card reader that I've been successfully using over the years, but it does not work anymore. I think the card has become corrupted, either because of a power failure or simply age has worn it out.

The Pi is still running fine, everything seems OK, I just cannot create an image from the SD card using Win32DiskImager anymore, which worries me a lot, because I have many important things on it which were not yet backed up.

Can you please suggest some alternative backup methods which might work? Is there some other backup software that can be used on Windows and which can skip the corrupted sectors (or whatever is causing the read error)? What about dd? I've seen that there's a version for Windows, would it be worth trying out dd? If yes, what would be the commands to:
1. Create a backup image of the card
2. Repair the bad sectors
3. Restore the backup image to the card

Thank you in advance for any helpful info you may be able to give me!
Andras
http://iqjar.com

beta-tester
Posts: 1334
Joined: Fri Jan 04, 2013 1:57 pm
Location: de_DE

Re: Backing up the SD card when Win32DiskImager fails

Fri Dec 26, 2014 9:38 am

depends on, what your old SD card is or is not able to do anymore...
- is it recognized by the card reader/opperating system (if not, i see no chance to recover any data)
- is its block/sector contend readable (block/sector based clone possible - dd, ddrescue, ...)
- is its partition and filesystem readable (file based clone/copy possible)

you can try dd or maybe ddrescue (it is a special version of dd, that has some feature to handle bad blocks - does continue copying if one found, but do not correct them!)...

if you still has access to the sd cards filesystem, you can alsotry to create a file based clone instead of a sector/block based clone...

NOTE: next time you made bigger important changes, make a backup immediately and write down on an other medium, what changes you made... :ugeek:
Last edited by beta-tester on Fri Dec 26, 2014 9:42 am, edited 1 time in total.
{ I only give negative feedback }
RPi B (256MB), B (512MB), B+, ZeroW; 2B; 3B, 3B+; 4B (4GB)

TrevorAppleton
Posts: 74
Joined: Wed May 30, 2012 7:26 pm
Contact: Website

Re: Backing up the SD card when Win32DiskImager fails

Fri Dec 26, 2014 9:41 am

You can use linux to back up your card using the dd command.

Follow the instructions on my blog which work equally well for linux as a mac. However rather than using dd to put an image on the card, use it to take the image off as below.

dd bs=1m if=~/dev/rdiskNumber of=/place/where/you/save/image.img

also I think the fsck command can fix errors on the disk, but do some research on it and back up first of all!

My blog post which will help is here.

http://trevorappleton.blogspot.co.uk/20 ... g-mac.html
Check out my blog post for Raspberry Pi and Python tutorials.

http://trevorappleton.blogspot.co.uk/

beta-tester
Posts: 1334
Joined: Fri Jan 04, 2013 1:57 pm
Location: de_DE

Re: Backing up the SD card when Win32DiskImager fails

Fri Dec 26, 2014 9:51 am

TrevorAppleton wrote:also I think the fsck command can fix errors on the disk, but do some research on it and back up first of all!
yes, very important,
DO A BACKUP BEFORE YOU MAKE ANY WRITE OPPERATIONS TO A DEMAGED FILESYSTEM!
{ I only give negative feedback }
RPi B (256MB), B (512MB), B+, ZeroW; 2B; 3B, 3B+; 4B (4GB)

User avatar
Un4Seen
Posts: 330
Joined: Wed Oct 31, 2012 8:43 am
Location: Cluj-Napoca, Romania
Contact: Website

Re: Backing up the SD card when Win32DiskImager fails

Fri Dec 26, 2014 9:54 am

The RPI can access the card just well.
Windows also accesses the card and Win32DiskImager can read it, except when it gets to 88%, there it stops and appears to work forever.
So I think the card is not badly damaged, just that bit at 88%.

I cannot use Linux to create an image of the card. Besides the RPI I only have a Win 7 machine at the location where this RPI is. To complicate things, this RPI is not in my home, but at a remote location where I can only be for a few hours per week. Today I can stay there for about 2 hours. So I need a solution which will work in those 2 hours. If I start researching on site, the time will pass and I will get nothing :) And I need something that will work on the Windows machine, not Linux :)
Andras
http://iqjar.com

User avatar
Un4Seen
Posts: 330
Joined: Wed Oct 31, 2012 8:43 am
Location: Cluj-Napoca, Romania
Contact: Website

Re: Backing up the SD card when Win32DiskImager fails

Fri Dec 26, 2014 9:59 am

beta-tester wrote:
TrevorAppleton wrote:also I think the fsck command can fix errors on the disk, but do some research on it and back up first of all!
yes, very important,
DO A BACKUP BEFORE YOU MAKE ANY WRITE OPPERATIONS TO A DEMAGED FILESYSTEM!
That's my exact problem, that I can't do a backup :(
Andras
http://iqjar.com

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

Re: Backing up the SD card when Win32DiskImager fails

Fri Dec 26, 2014 10:00 am

Un4Seen wrote:The RPI can access the card just well.
Windows also accesses the card and Win32DiskImager can read it, except when it gets to 88%, there it stops and appears to work forever.
So I think the card is not badly damaged, just that bit at 88%.

I cannot use Linux to create an image of the card. Besides the RPI I only have a Win 7 machine at the location where this RPI is. To complicate things, this RPI is not in my home, but at a remote location where I can only be for a few hours per week. Today I can stay there for about 2 hours. So I need a solution which will work in those 2 hours. If I start researching on site, the time will pass and I will get nothing :) And I need something that will work on the Windows machine, not Linux :)
Use a Linux LiveCD or LiveUSB to boot up the Windozy Machine ;)
Retired disgracefully.....
......to an uncomplicated life !

Rather than negativity think outside the box !

beta-tester
Posts: 1334
Joined: Fri Jan 04, 2013 1:57 pm
Location: de_DE

Re: Backing up the SD card when Win32DiskImager fails

Fri Dec 26, 2014 10:04 am

the quickest solution...
buy a second SD card, install a fresh basic system to it (Raspbian)...
if you onsite to your RPi physically, exchange the old SD card with the new SD card...
now, you have more time to try to rescue your old SD card...

i really would suggest to use ddrescue it will not stop if a bad block is found, and i guess it is as fast as dd normally... should be finished in less than 2hours, depending on how big your SD card is.

if you are not onsite to your RPi, you can try to make a filebased backup (cp, rsync, tar, or what ever) remotely...
{ I only give negative feedback }
RPi B (256MB), B (512MB), B+, ZeroW; 2B; 3B, 3B+; 4B (4GB)

User avatar
Un4Seen
Posts: 330
Joined: Wed Oct 31, 2012 8:43 am
Location: Cluj-Napoca, Romania
Contact: Website

Re: Backing up the SD card when Win32DiskImager fails

Fri Dec 26, 2014 10:08 am

Thank you!

Yes, the remote file-based backup may work... although I don't really know how I can make sure that ALL files are copied (system files, hidden files, etc.)

The live USB Linux is also a good idea.

The SD card is 8GB and I do have an identical new one :)
Andras
http://iqjar.com

User avatar
rpdom
Posts: 16383
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Backing up the SD card when Win32DiskImager fails

Fri Dec 26, 2014 10:14 am

I'd use the Pi with a USB card reader, partition a new card with fdisk, make filesystems on it in mkfs.vfat and mkfs.ext4, then mount the partitions and use cp for /boot and rsync for / to copy the contents over. It will probably be a little faster than copying over the entire content of the card as unused space won't be copied. With luck the bad parts will be in the unused areas.
I think rsync can be told to continue even if it hits errors.

User avatar
Un4Seen
Posts: 330
Joined: Wed Oct 31, 2012 8:43 am
Location: Cluj-Napoca, Romania
Contact: Website

Re: Backing up the SD card when Win32DiskImager fails

Fri Dec 26, 2014 10:20 am

rpdom wrote:I'd use the Pi with a USB card reader, partition a new card with fdisk, make filesystems on it in mkfs.vfat and mkfs.ext4, then mount the partitions and use cp for /boot and rsync for / to copy the contents over. It will probably be a little faster than copying over the entire content of the card as unused space won't be copied. With luck the bad parts will be in the unused areas.
I think rsync can be told to continue even if it hits errors.
Sounds good. How many and what kind of partitions should be created?
Andras
http://iqjar.com

User avatar
Un4Seen
Posts: 330
Joined: Wed Oct 31, 2012 8:43 am
Location: Cluj-Napoca, Romania
Contact: Website

Re: Backing up the SD card when Win32DiskImager fails

Fri Dec 26, 2014 10:37 am

Is there a way to use fsck or something else on the card from which the Raspbian is running while it's running? At least to test/fix the unused space?
Andras
http://iqjar.com

User avatar
rpdom
Posts: 16383
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Backing up the SD card when Win32DiskImager fails

Fri Dec 26, 2014 10:44 am

Un4Seen wrote:Sounds good. How many and what kind of partitions should be created?
Best to make it identical to the original card, or as close as possible - the last partition may need to be slightly smaller if the new card hasn't got the same capacity.

sudo fdisk -l will show you the details of the card that is running.
This is an example of a Pi that was installed from a plain Raspbian image on an 8GB card and the filesystem expanded with raspi-config:

Code: Select all

[email protected] ~ $ sudo fdisk -l

Disk /dev/mmcblk0: 7.4 GiB, 7948206080 bytes, 15523840 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00014d34

Device         Boot  Start      End  Sectors  Size Id Type
/dev/mmcblk0p1        8192   122879   114688   56M  c W95 FAT32 (LBA)
/dev/mmcblk0p2      122880 15523839 15400960  7.4G 83 Linux
I don't have an example of a NOOBS set up yet, but I'm hoping to get another card and maybe another Pi some time soon to test things on.

beta-tester
Posts: 1334
Joined: Fri Jan 04, 2013 1:57 pm
Location: de_DE

Re: Backing up the SD card when Win32DiskImager fails

Fri Dec 26, 2014 12:27 pm

in case you make a file based clone/copy,
the following folders of your root partition you should not copy:
/boot/
/dev/pts/
/media/
/proc/
/sys/

mount an USB stick to /media/my_USB_stick
my_USB_stick is a name of your choice
(possibly it is automatically done by system, when you plug the usb stick).

Code: Select all

sudo tar -cvpaf /media/my_USB_stick/root.tar.xz /* --exclude=/boot/* --exclude=/dev/pts/* --exclude=/media/* --exclude=/proc/* --exclude=/sys/*
that will create a filebased backup of the root filesystem to a compressed tar.xz archive on your usb stick.

Code: Select all

cd /boot/
sudo tar -cvpaf /media/my_USB_stick/boot.tar.xz .
that will create a filebased backup of the boot filesystem to a compressed tar.xz archive on your usb stick.
Last edited by beta-tester on Fri Dec 26, 2014 1:36 pm, edited 3 times in total.
{ I only give negative feedback }
RPi B (256MB), B (512MB), B+, ZeroW; 2B; 3B, 3B+; 4B (4GB)

User avatar
Un4Seen
Posts: 330
Joined: Wed Oct 31, 2012 8:43 am
Location: Cluj-Napoca, Romania
Contact: Website

Re: Backing up the SD card when Win32DiskImager fails

Fri Dec 26, 2014 12:28 pm

Thank you very much :)
I've never used NOOBS, my Pi cards are much older than NOOBS ;)
Andras
http://iqjar.com

User avatar
rpdom
Posts: 16383
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Backing up the SD card when Win32DiskImager fails

Fri Dec 26, 2014 1:43 pm

beta-tester wrote:

Code: Select all

sudo tar -cvpaf /media/my_USB_stick/root.tar.xz /* --exclude=/boot/* --exclude=/dev/pts/* --exclude=/media/* --exclude=/proc/* --exclude=/sys/*
that will create a filebased backup of the root filesystem to a compressed tar.xz archive on your usb stick.

Code: Select all

sudo tar -cvpaf /media/my_USB_stick/root.tar.xz  --one-file-system /*
Is a lot easier to type and will do the same job :)

I'd add in --exclude=/tmp/* --exclude=/var/tmp/* as well though, as you don't need to keep anything in those two temporary directories.

User avatar
Un4Seen
Posts: 330
Joined: Wed Oct 31, 2012 8:43 am
Location: Cluj-Napoca, Romania
Contact: Website

Re: Backing up the SD card when Win32DiskImager fails

Fri Dec 26, 2014 8:36 pm

Thank you all for your kind help!

I've tried a lot of things today, at least 6 different pieces of software to make a copy, but none could handle the problem, not even dd.
In the end I ended up restoring a backup from the 30th of November onto a brand new card and dumping the whole MySQL DB from the broken card (on which the Raspbian was still running) and importing it into the new instance of the OS running on the new card. I manually copied some other files too. In the end all I lost were the comments from December on my WordPress blog. I did not have the time to figure out how to back up and restore the WordPress DB. Fortunately I had no new posts in December, so only some comments were lost.
Andras
http://iqjar.com

beta-tester
Posts: 1334
Joined: Fri Jan 04, 2013 1:57 pm
Location: de_DE

Re: Backing up the SD card when Win32DiskImager fails

Sat Dec 27, 2014 8:56 am

Un4Seen wrote:I've tried a lot of things today, at least 6 different pieces of software to make a copy, but none could handle the problem, not even dd.
event dd, and what was with ddrescue...?
that specially is made for that cases. :? :P
{ I only give negative feedback }
RPi B (256MB), B (512MB), B+, ZeroW; 2B; 3B, 3B+; 4B (4GB)

User avatar
Un4Seen
Posts: 330
Joined: Wed Oct 31, 2012 8:43 am
Location: Cluj-Napoca, Romania
Contact: Website

Re: Backing up the SD card when Win32DiskImager fails

Sun Dec 28, 2014 5:54 pm

Could not try ddrescue because I could not boot the live Linux stick.. I used dd for Win.
Andras
http://iqjar.com

VojtechU
Posts: 1
Joined: Fri Mar 11, 2016 11:15 am

Re: Backing up the SD card when Win32DiskImager fails

Fri Mar 11, 2016 11:20 am

Hi,
I had the same problem. Use HDDRawCopy it solved my problem.
http://hddguru.com/software/HDD-Raw-Copy-Tool/

Return to “Troubleshooting”