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)?