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