# Filesystem corrupted during backup

## Rinne

Hi all,

I have a rather tricky situation and didn't find a solution yet.

I tried to backup my home folder to an external hdd. Unfortunately I was dumb enough to do so via 

```
cp -R /home/* ....
```

 in a terminal.

The folder contained some invalid filenames with special characters that were placed by applications and gave out messages they would be ignored.

During the copy process my machine locked up and after not responding for quite some time, I did a hard power-off.

When I booted back up, my home folder was corrupted. As in, a lot of (random) files and folders were missing. As far as I can see all Symlinks are broken as well.

Despite being on the same partition as the root system, only my home folder is affected, and only to a degree that I can still use most things.

Apparently only two files have been copied to the external hdd.

Most important files are intact, but my thunderbird profile including all mail is gone which I'd really like to restore.

Does anyone have an idea what could have happened?

Any possible solutions?

Both source and target filesystems were ext4.

The source hdd is a ssd. I know it can make recovery hard/impossible.

Immediately after I noticed the errors (so immediately after boot) I shut down and booted to a rescue system. Then cloned the whole partition to the external hdd. Not sure if that's of any help.

Best regards and thanks in advance

Rinne

----------

## jonathan183

using cp should not have been a problem unless you managed to specify some part of the /home folder as the destination. What was the exact command you typed at the terminal?

Your best hope is to mount the drive read only, boot from a live CD until you have finished trying to save data.

I dont have an ssd drive but have found testdisk has done a good job in the past.

My strategy would be to boot from a live cd like systemrescueCD, mount the ssd partition read only, copy readable information somewhere else (like an external hard drive), unmount the ssd, run testdisk on it and try to find the missing information. Copy all useful information to an external hard drive, then work out what caused trashing of the filesystem ...

----------

## eccerr0r

You probably had some hidden corruption in your SSD that the copy uncovered.  What kernel are you using (I remember a version of the kernel had a bad ext4 driver that could have caused corruption.

Curious what brand of SSD is it?

----------

## Irre

I think the combination ext4 and ssd is really really bad  :Evil or Very Mad:   The filesystem was not possible to recover. It has happened to my three Raspberry PI (early models with sd-cards).

And much worse it happened to my: mobile phone! Google Nexus 5 with Android 5.1.1 which uses the ext4 file system   :Twisted Evil:  I think I lost hundreds of dollars there. I was able to reflash the system but the corrupted ext4 file system remains.   :Crying or Very sad: 

----------

## NeddySeagoon

Irre,

That's a feature of the early Pis.  The SD Cards can embarrass the PSU if you use a phone charger as the PSU.

If you provide power through the expansion header, its not an issue.

----------

## Irre

 *NeddySeagoon wrote:*   

> If you provide power through the expansion header, its not an issue.

  That problem is gone as I only use the SD-cards read only now. The linux file systems are all moved to external usb-disks.   :Smile: 

----------

## NeddySeagoon

Irre,

I do that too ... and root over NFS  :)

----------

## eccerr0r

I use ext4 on my real SSDs with trim enabled, and they work fine.  I probably got lucky and didn't install the broken version of the kernel, but ext4 seems to work fine for me (setup three ext4 Linux root partitions on a Crucial and two Intel SSDs).

I do have to say that SD (micro SD, SDHC, all of them) cards which I will not call "SSD" because they tend to be really horrible in terms of reliability.  I've lost several of these cards over the years after they wear out prematurely (or at least I feel that to be the case.)  CF cards seem much more reliable for me over the years.

I don't have much of an opinion yet about eMMCs that were meant to be used as root filesystems for OS.  I kind of doubt they know how to trim, and I doubt they have write buffering so they are doing write through...  Of the eMMCs that I do have and used extensively, so far so good...

----------

## Buffoon

Maybe flash media is better now, but ext4 journaling could kill earlier chips.

----------

## Irre

 *Buffoon wrote:*   

> Maybe flash media is better now, but ext4 journaling could kill earlier chips.

 

Maybe the f2fs file system "Samsung's Flash Friendly File System" is something to consider  :Question: 

http://forum.xda-developers.com/showthread.php?t=2697069

----------

## krinn

 *Rinne wrote:*   

> I tried to backup my home folder to an external hdd. Unfortunately I was dumb enough to do so via 
> 
> ```
> cp -R /home/* ....
> ```
> ...

 

Generally you don't need to seek errors beyond the ones of the user.

cp source target, read only source. If source gets corrupt it's because user did something bad, like using his source also as target.

I don't think any SSD controller would start trimming when the device is busy reading (that would cut its perf down).

You won't be the first to do a mistake, and people keep rm that or this directory because of a simple mistake.

You should look at your bash history.

----------

## eccerr0r

I'm not sure if using cp could ever result in corrupted filenames, this is more due to either media or OS/filesystem failure.  

SSDs also have SMART that you can access with smartmontools, make sure you don't have media wear.  Most modern SATA SSds have meaningful data indicating how worn the SSD is, and should expect errors if it's worn out.  Again if this is a SD* media, all bets are off.  I'm not even convinced wear leveling in SD* media is very good...

----------

## Roman_Gruber

backups with

cp -axr

are working fine. and even boot here.

I only have this plextor ssd PLEXTOR PX-128M3, but it was hell expensive as i bought it, and still is far decent regarding online benchmark homepage.

----------

## Rinne

Hi all, thanks for the plenty replies and hints.

I have recovered all of my important files from other sources in the mean time and don't need to try and recover anything anymore.

I'll answer everything anyways.

I tried to use fsck but it didnt find any corruption. Also did some more checks on the cloned partition, but not sure if that can even bring out errors.

I just used cp from my ssd to an external drive. My bash history is:

```

475 groups rinne

476 su   # Worked as root here, this session was ended before the following though

477 cd ..

478 ls

479 cp -R rinne/ /run/media/rinne/35B1-C589/HOME/   # Failed because of invalid filenames, aborted with ctrl+x

480 cp -R "rinne/" "/run/media/rinne/35B1-C589/HOME/"   # Failed again. I don't know why I even tried

481 cp -help

482 cp --help

483 cp -R * /run/media/rinne/35B1-C589/HOME/ # This is where it went bad. (Current folder I cp -R * on is /home, btw.)

```

The drive I use is a 256GB Crucial M4.

My Kernel is 4.0.5

Smartmontools says Everything is fine, but I'm running the offline test etc. now.

I will also looking into migrating to F2FS.

Thanks a lot.  :Smile: 

----------

## eccerr0r

I'd look into making sure your RAM is good too in this case...

(I had a 128G Crucial M4, also run ext4fs on it... no problems... gave it away after upgrading.)

----------

