I usually avoid proprietary cloud services because of freedom, privacy and vendor lock-in concerns. In addition, there are some excellent libre (and hosted) services such as WordPress, Wikipedia and OpenShift which don’t have the above problems. Thirdly, there are every day Free Software tools such as Fedora GNU/Linux, Libreoffice, and git-annex-assistant which make my computing much more powerful. Finally, there are some hosted services that I use that don’t lock me in because I use them as push-only mirrors, and I only interact with them using Free Software tools. The two examples are GitHub and Dropbox.
Today, Dropbox bit me. Here’s how I saved my data.
Dropbox integrates with GNOME‘s nautilus to sync your data to their proprietary cloud hosting. I periodically run the dropbox client to sync any changes to my public files up to their servers. Today, the client decided that some of my newer files were older than the stored server-side versions, and promptly over-wrote my newer versions.
Thankfully I have real backups, and, to be fair, Dropbox actually renamed my newer files instead of blatantly clobbering them. My filesystem now looks like this:
$ tree files/ files/ |-- bar |-- baz | |-- file1 | |-- file1\ (james's\ conflicted\ copy\ 2014-09-29) | |-- file2\ (james's\ conflicted\ copy\ 2014-09-29).sh | `-- file2.sh `-- foo `-- magic.sh
You’ll note that my previously clean file system now has the “conflicted copy” versions everywhere. These are the good versions, whereas in the example above file1 and file2.sh are the older unwanted versions.
I spent some time with find and diff convincing myself that this was true, and eventually I wrote a script. The script looks through the current working directory for “conflicted copy” matches, saves the unwanted versions (just in case) and then clobbers them with the good “conflicted” version.
Please look through, edit, and understand this script before running it. It might not be what you want, and it was designed to only work for me. It is available as a gist, and below in the body of this article.
$ cat fix-dropbox.sh
#!/bin/bash
# XXX: use at your own risk - do not run without understanding this first!
exit 1
# safety directory
BACKUP='/tmp/fix-dropbox/'
# TODO: detect or pick manually...
NAME=`hostname`
#NAME='myhostname'
DATE='2014-09-29'
mkdir -p "$BACKUP"
find . -path "*(*'s conflicted copy [0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]*" -print0 | while read -d $'' -r file; do
printf 'Found: %s\n' "$file"
# TODO: detect or pick manually...
#NAME='XXX'
#DATE='2014-09-29'
STRING=" (${NAME}'s conflicted copy ${DATE})"
#echo $STRING
RESULT=`echo "$file" | sed "s/$STRING//"`
#echo $RESULT
SAVE="$BACKUP"`dirname "$RESULT"`
#echo $SAVE
mkdir -p "$SAVE"
cp "$RESULT" "$SAVE"
mv "$file" "$RESULT"
done
You can thank bash for saving your data. Stop bashing it and read this article instead.
Happy hacking,
James
Please note: About the “Stop bashing it” link above, I agree with what was written in that article, but nothing else about the author. I didn’t/don’t know about his background.
In my case I have had conflicted copies because Dropbox thought I had changed them as well as another machine sharing that folder had changed them, which was not the case. My conflicted copies are in reality older than the latest versions and should be ditched. So you need to be careful to determine which should be ditched and which retained.
Also I’m no bash guru, so I might be teaching grandmother to suck eggs. I picked up a useful tip in a book I read on bash programming. Use this statement to help catch undefined variables in your code (hope it helps): shopt -s -o nounset
(As an aside: It took me a while to find the do in your code till I realised there was a scroll bar along the bottom!)