Distribute backups to local machines

If you are a team as ours you are probably working remotely, with laptops, anywhere you can, anytime you can. This mean that all of our machines are “on the cloud”, they do run, scale and backup entirely automatically.

But what if you want to add one more line of defense – copying the backups locally to your machine from time to time. In this way even if in sequence of unlikely and strange events that corrupt your remote machines, you would have a local backup of your important information. But as in our case most of the time we forget to do a copy to a local machine. That’s why I would like to make it automatic.

What we are currently doing is copying a backup from remote to local every time your machine starts its Internet interface. And yes, this would would not scale for GB backups. But we are still not there.

This is the script:

#! /bin/sh

# Copies production_backup on this machine

# This script should be copied at /etc/network/if-up.d/. In this way everytime the network starts a backup would be made
export REPOSITORY=/home/kireto/robopartans/rbp.cm
export USER_WITH_ACCESS=kireto


echo “Starting script:” >> /tmp/production_backup_copy.log
set -e


# Don’t bother when lo is configured.
if [ "$IFACE" = lo ]; then
exit 0


#~ # Only run from ifup.
if [ "$MODE" != start ]; then
exit 0


FILE=”production_backup$(date +’%Y_%m_%d’).sql.gz”
REMOTE_PATH=”\”/var/jenkins/jobs/Production\\ backup/workspace/$FILE\”"

if [ -f $LOCAL_PATH ]; then
echo “File exists locally” >> /tmp/production_backup_copy.log
exit 0


sudo su – $USER_WITH_ACCESS -c “cd $REPOSITORY; scp root@elvis:$REMOTE_PATH .”
echo “Pulling at: $(date +”%D %T”)” >> /tmp/production_backup_copy.log

exit 0

This script is then added at


Now we have a distributed backup system, where simultaneous fail of all the machines and processes is impossible (except if someone starts a earth big Electromagnetic impulse)

Leave a Comment

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>