I was editing a script I wrote some time ago to automatically backup the contents of my Raspberry Pi SD card, and in the course of editing, I missed a "/", and so here is the entire shell script:
#!/bin/bash
date
echo BACKING UP RASPBERRY PI
sudo dd if=/dev/mmcblk0p2 of=/media/USBDRIVE/RPi-Backups/RPi-Backup-$(date +"%m_%d_%Y").img bs=10M
echo COMPRESSING RASPBERRY PI BACKUP
sudo gzip -9 -c /media/USBDRIVE/RPi-Backups/RPi-Backup-$(date +"%m_%d_%Y").img > /media/USBDRIVE/RPi-Backups/RPi-Backup-$(date +"%m_%d_%Y").img.gz
and once I did this, I realized that I made a mistake and stopped the script. I checked the directory where my backups are kept, and they were all gone. What was strange, was that there was as much space taken up in the drive as there had been before I ran the script, about half the 500 GB USB drive.
As far as I can tell, the backups are gone, which kind of undermines the whole point of the backups.
Is there a way to recover these files?
If not, is there a way to recover the space without wiping and reformatting the drive?
Update 1/2015: This has since happened to me on a brand new drive, different make and model, in both cases making over 200 GB simply disappear, with the space still somehow in use. To happen twice in a row, with two different drives made by two different manufacturers seems fairly unlikely. Could there be something in my backup script causing these failures? If the files are truly gone, why is the directory still there? Why does the disk and OS still think that the same amount of space is still in use as opposed to just calculating it as if the files were wiped (since they are apparently gone)?
dd
: no problem. And why should a problem with the input path delete your backups? You should run your script throughbash -vx script
and show us the output (edit your question). – Hauke Laging May 20 '14 at 03:40of
part that can overwrite, not theif
. In any case, as Hauke pointed out, the//
is irrelevant, it will be ignored. – terdon May 20 '14 at 03:41.img
and.img.gz
files, but that's the only modifications it does. Something else deleted them. – Barmar May 20 '14 at 04:41//dev
is equivalent to/dev
(except in some exotic settings such as Cygwin, but nothing that would affect you). There are some oddities in your script, like callingsudo
to rungzip
and not compressing on the fly, but they wouldn't explain the files disappearing. If you yanked the stick out without unmounting at some point, that could explain it. Are you sure there wasn't another editing mistake that you fixed since then? – Gilles 'SO- stop being evil' May 20 '14 at 23:13