Centralized Backup Script

Hello There!

I thought I’d share a backup script that was written to consolidate backups onto one server instead of spreading the backup process across several servers. The advantages are somewhat obvious to consolidating the script onto one server, namely being that editing or making changes is much easier as you only have one script to edit.

The environment where this may be ideal would be for environments with 15-20 servers or less. I’d recommend a complete end-to-end backup solution for servers that exceed that number such as Bacula perhaps.

The bash shell script that I pasted below is very straightforward and takes two arguments. The first is the hostname or ip address of the destination server you are backing up. The next (and potentially unlimited) arguments will be single quote encased folders which you would want backed up.

This script is dependent on the server the script is running on having ssh key based authentication enabled and implemented for the root user. Security considerations can be made with IP based restrictions either in the ssh configuration, firewall configuration or other considerations.

It should be explained further that this script actually connects to the destination server as the root user, using ssh key authentication. It then initiates a remote rsync command on the destination server back to the backup server as a user called “backupuser”. So that means that not only does the ssh key need to be installed for root on the destination servers, but a user called “backupuser” needs to be added on the backup server itself, with the ssh keys of all the destination servers installed for the remote rsync.

Hopefully I did not over complicate this, because it really is quite simple :

Backup Server –> root –> destination server to backup — > backupuser rsync –> Backup Server

Once you implement the script and do a few dry run tests then it might be ready to implement a scheduled task for each destination server. Here is an example of one cron entry for a server to be backed up :

Massive Amazon Route53 API Bind Zone Import Script

Hello there,

Occasionally some of our managed services work has us dealing directly with other cloud providers such as Amazon. One of our clients set a requirement to migrate over 5,000 domain’s to Amazon’s Route53 DNS service.

There was little doubt that this could be automated, but since we have never done this massive of a deployment through Amazon’s API directly, we thought it might be interesting to post the process as well as the script through which we managed the import process.

Essentially the script utilizes a master domain name list file as its basis for looping through the import. The master list refers to the bind zone files and imports them into Amazon’s Route53 via the Cli53 tool package.

One final note, the script outputs all completed domain imports into a CSV file with the following format :

This is because when facilitating the actual nameserver change request, all the nameservers assigned to domains when imported to Route53 are randomly generated, so the script has to keep track of these nameserver/domain associations.

The script isn’t perfect and could benefit from some optimizations and more error checking (it does a lot of error checking already, however), but here it is in its entirety. We hope you will have some use for it!

Automatically Deploy Debian Load Balancers with bash scripting

In yet another post in our automation series, we will share a bash script that automates the deployment of debian based load balancers (specifically with LVS / Linux Virtual Server project).

Even though the environments and systems you deploy may start to get more complicated such as with load balancers, there will always be a baseline level with which these systems can be brought to before further configuration and customization needs to be done.

There are many things that can be automated with this process, as you will see in the script below. In most round-robin load balancing scenarios, there wouldn’t be much more that needs to be done as far as configuration beyond what this script can do.

Obviously you will likely need to modify the script to suit your needs and requirements for the organization and standards therein.

Hopefully this will help you roll out many debian load balancers! May the load be split evenly between all your systems 😉

[cc lang=”bash”]

#!/bin/sh
# Debian LVS deployer script
# Version 1.0

PROGNAME=”$0″
VERSION=”1.0″

# working directory for deployer process.
WORKDIR=”/root”

# tasks left (this is updated every step to accommodate recovery during
# the deployer process)
TASKS=”./deploy-lvs.tasks”

init_tasks() {
# This function will write a new tasks file.
# it’s called from the main body of the script if a tasks file does not exist.
cat > $TASKS<hostname > /etc/hostname
echo hostname > /etc/mailname
return 0
}

usage() {
echo “[+] Usage: $PROGNAME”
echo
return 0
}

###############################
### MAIN SCRIPT STARTS HERE ###
###############################

# installer_splash
installer_splash

# fix working dir.
cd $WORKDIR

# does our installer file exist? if not, initalize it.
if [ ! -f $TASKS ]
then
echo “[+] No task file found, installation will start from beginning.”
init_tasks
if (($? != 0))
then
echo “[!] ERROR: Cannot create tasks file. Installation will not continue.”
exit 1
fi
else
echo “[+] Tasks file located – starting where you left off.”
fi

# start popping off tasks from the task list and running them.
# pop first step off of the list
STEP=head -n 1 $TASKS
while [ ! -z $STEP ]
do
# execute the function.
echo -e “nn###################################”
echo “[+] Running step: $STEP”
echo -e “###################################nn”
$STEP
if (($? != 0))
then
# command failed.
echo “[!] ERROR: Step $STEP failed!”
echo ” Installation will now abort – you can pick it up after fixing the problem”
echo
exit 1
fi
# throw up a newline just so things don’t look so crowded
echo
# remove function from function list.
perl -pi -e “s/$STEPn?//” $TASKS || exit 1
STEP=head -n 1 $TASKS
done

# clean_up_and_reboot
echo “[+] Installation finished – cleaning up.”
clean_up_and_reboot

# script is done now – termination should happen with clean_up_and_reboot.
echo “[!] Should not be here!”
exit 1
[/cc]