Almost 9 months after the fact, my post about automating server backups to SpiderOak has proven to be popular amongst Googlers, so I thought it was time to update it with the latest build of my script.
If you don’t have SpiderOak yet, you can download it using this link to start with 3GB of space. If you decide you want to purchase a plan for more storage space, I recommend checking out their Facebook page where they currently have a promo code there worth 20% off all of their plan options.
You can find instructions for setting up the Linux client on their site.
Next, download, configure and save my backup script to your server. The latest version of this script can be found on my /scripts repo at GitHub, and I warmly welcome any contributions users make to it, be it bug fixes or new features.
#!/bin/bash
# Automated Cloud Backups to SpiderOak
# -----
# Feel free to use this in any environment and
# modify it to your heart's content.
# -----
# Author: Evan Sims <hello@evansims.com>
# Updates: https://github.com/evansims/scripts/
##### START OF CONFIGURATION ####
# MySQL Database:
mysqlUser=""
mysqlPass=""
# MongoDB Database:
mongoUser=""
mongoPass=""
mongoHost=""
# Backup target directory:
backup="/home/username/backups/"
# Backup these directories or files:
folders[0]="/home/username/files/"
folders[1]="/var/logs/"
# If you're doing backups to a git repo and want to commit
# these updates, enable this.
gitCommit=0
gitPushRepo="" # git push $gitPushRepo
# 7 day backups are the default.
# Your $backup directory will be filled with Monday, Tuesday, etc. folders.
# Each weekday folder will be overwritten when the backup cycles around.
stamp=$(date -u +%A)
backupCurrent=$backup$stamp
# OR uuncomment the following lines for ~30 day backups.
# Your $backup directory will be filled with folders labled 01 through 31
# representing each day of the month.
#stamp=$(date -u +%d)
#backup=$backup$stamp
# OR uncomment the following lines for unlimited backups.
# Your $backup directory will have a new folder created for each day
# a backup is built. Keep an eye on space usage if you're going to use
#this method.
#stamp=$(date -u +%F)
#backup=$backup$stamp
##### END OF CONFIGURATION ####
temp="$PWD/backup.tmp"
echo "Starting Backup..."
if [ ! -d "$backupCurrent" ]; then
mkdir "$backupCurrent"
fi
if [ ! -d "$backupCurrent/mongodb" ]; then
mkdir "$backupCurrent/mongodb"
fi
if [ ! -d "$backupCurrent/mysql" ]; then
mkdir "$backupCurrent/mysql"
fi
if [ -z $mongoUser ] && [ -z $mongoPass ]; then
echo "-----"
echo -ne "Exporting MongoDB collections ... "
mongodump -h $mongoHost -u $mongoUser -p $mongoPass -o "$backupCurrent/mongodb" 2>"$temp" >/dev/null
tar -cjf "$backupCurrent/mongodb.tar.bz2" "$backupCurrent/mongodb/"* 2>"$temp"
rm -R "$backupCurrent/mongodb/"*
mv "$backupCurrent/mongodb.tar.bz2" "$backupCurrent/mongodb/mongodb.tar.bz2"
echo "Done."
fi
if [ -z $mysqlUser ] && [ -z $mysqlPass ]; then
echo "-----"
echo -ne "Preparing to backup MySQL ... "
databases=( $(mysql -u"$mysqlUser" -p"$mysqlPass" --skip-column-names --batch -e "show databases;" 2>"$temp") );
echo "found ${#databases[@]} databases.";
for i in ${databases[@]}; do
if [ $i != "information_schema" ] && [ $i != "mysql" ] && [ $i != "phpmyadmin" ]; then
echo -ne "Optimizing and backing up database $i ... "
mysql -u"$mysqlUser" -p"$mysqlPass" -D "$i" --skip-column-names --batch -e "optimize table $i" 2>"$temp" >/dev/null
mysqldump -u"$mysqlUser" -p"$mysqlPass" --opt $i | bzip2 -c > "$backupCurrent/mysql/$i.sql.bz2"
echo "Done."
fi
done
fi
echo "-----"
for f in "${folders[@]}"
do
if [ -d "$f" ]; then
echo -ne "Backing up directory $f ... "
d=$(basename $f)
d="$d.tar.bz2"
elif [ -f "$f" ]; then
echo -ne "Backing up file $f ... "
d=${f##*/}
d="$d.tar.bz2"
else
echo "Error! $f could not be found."
exit 1
fi
tar -cjf "$backupCurrent/$d" -C / ${f:1}
echo "Done."
done
if [ ! -s $temp ]; then
rm -f "$temp"
fi
if [ -z $gitCommit ]; then
cd $backup
echo "-----"
echo "Committing changes to git ... "
git add .
git commit -m "Backup $stamp"
if [ -z $gitPush ]; then
git push $gitPush
fi
echo "Done."
fi
echo "-----"
echo -ne "Pushing data to SpiderOak ... "
SpiderOak --empty-garbage-bin 2>"$temp" >/dev/null
SpiderOak --batchmode 2>"$temp" >/dev/null
SpiderOak --purge-historical-versions all 2>"$temp" >/dev/null
SpiderOak --vacuum 2>"$temp" >/dev/null
echo "Done."
echo "-----"
echo "Backup Complete!"
exit 0Setup this script to run as a Cron task once a day, during a period of time that your machine won’t be being actively used. In the case of a web or database server, I’d recommend graphing your access logs and seeing when you have the lowest point of traffic on average, and run it during this time.
Although this script is designed for Linux, and makes use of the SpiderOak Linux client’s command interface, I believe the OS X client supports the same commands. The script could potentially be modified to support Mac with relative ease.
I hope folks out there find this useful. Have fun.


On the surface, Zerply is just an attractive alternative to LinkedIn or about.me. The service does have a few clever tricks up it’s sleeve, though. Zerply builds a network around your contacts and users who share similar skills and experiences. Individuals in your network appear on your homepage in a seemingly random fashion (or perhaps sorted by most recent profile editing; this isn’t made clear.) If they build this functionality out, it could be a useful mechanism for discovering new contacts. Likewise this functionality could be used by recruiters to quickly filter individuals with certain skill sets.
One feature I’m especially fond of is their widget. It’s a JavaScript widget that comes in two flavors, and allows people to one-click endorse you for a skill. If I wrote a technical article about the Twitter API, for example, and embedded this widget a user might think it was particularly insightful and endorse me on my “programming” skill. These endorsements appear next to skill tags in the Zerply network. I think this opens up a lot of interesting possibilities, especially for bloggers.
Listening
Playing
Popular Posts
Twitter
Subscribe