PEBS: Pug’s Extensible (Remote) Backup System
I had a hard drive on my computer here have a complete head crash last weekend. Luckily, I’m a paranoid freak who runs his desktop with a RAID array, so no important data was lost. However, I realized over the week (while waiting for the replacement drive to arrive) that I have several places on the Internet to where I could do offsite backups of my most critical data if only I trusted them with the data.
Well, I had a bit of a brainstorm yesterday and I wrote a series of BASH scripts which I am actually rather impressed with which I’m titling PEBS: Pug’s Extensible Backup System.
Features:
- Written in BASH with minimal dependencies
- Provides a simple scripting language for defining what you’d like backed up
- Can be used on a multi-user system with each user defining what files they would like backed up via the scripting system (this is unsecure, presently, though)
- Uses GPG and your public key to encrypt the final backup archive before transmitting it to the remote host
Executive Summary for Interested Parties (Read!)
PEBS provides an infrastructure for remote, encrypted backups. Proper use of PEBS is going to require you to be comfortable with the “tar” command and have a basic knowledge of how to edit a shell script.
What PEBS does is takes care of backup naming, data encryption, data transfer to the remote server and verification of successful transfer. It also provides some logging of the results. If you’ve questions, look at the script example below for an idea of how to use this tool.
Download:
Requirements:
- A unix-like system
- GnuPG (for encryption)
- OpenSSH (for secure data transfer)
- GNU Tar (for backup storage)
- GZip (for backup compression)
- OpenSSH must be setup with an automatic authentication method, such as a public key cryptography
Configuration consists of two steps, configuring the script’s overall options and writing one or more backup definition script.
The overall configuration is pretty easy. You fill in values in this file:
#!/bin/bash # PEBS - Pug's Extensible Backup System # Copyright (C) 2006 James C. Jones # # Backup infastructure written by James 'Pug' Jones# on 13 January 2006. These scripts are licensed under the GNU GPL # version 2 or later. See the included LICENSE file. # # These scripts use GPG, OpenSSH, BASH and Moshe Jacobson’s “color” shell # utility. “color” can be obtained at http://www.runslinux.net/projects.html # #Remote Backup Constants — You’ll have to change these. ######################## # This is the email address attached to your GPG public key. If this isn’t # correct, the script will fail on encryption encryptEmail=jcjones@ufl.edu # This is the SSH host (and username, if needed) where you want remote # backups to be copied using SCP. # An example may be “backup-account@myoffsitebackups.net” remoteHostName=”backup-account@myoffsitebackups.net” #Constants — You shouldn’t need to change these. ######################## # The tempDirectory is the root directory where all scripts should be told to # perform their backups. I suggest the /tmp/ dir. tempDirectory=/tmp/BackupLocation # This defines where the backup script files are located. Should not need # changing. scriptDir=$(pwd)/individual_scripts # This defines where the PEBS log is kept. logFile=$(pwd)/PEBS_backup_log # The date format. This format is simply the abbreviation of the day of the # week which makes PEBS overwrite last week’s logs without any extra # configuration. date=$(date +%a) # The final tar name. This is purely cosmetic. finalTar=”Backup-$(hostname -s)-$date.tar”
The script files look something like this:
#!/bin/bash # This file has inline documentation to discuss the two major script functions # which make PEBS do its thing. There are also examples for you to model your # scripts upon. # doMakeTar takes N arguments - the first argument MUST be a .tar file in # the $scriptTempDirectory. The remaining arguments are path arguments to the # tar command, e.g. directories to backup. The following example backs up # some important things on my computer's home directory. # backup files from my home directory doMakeTar $scriptTempDirectory/blah-homedirectory-$date.tar \ /home/blah/.config\ /home/blah/.gaim\ /home/blah/.fpm\ /home/blah/.*rc\ /home/blah/.gnupg\ /home/blah/.ssh\ /home/blah/.emacs\ /home/blah/.bashrc\ /home/blah/GnuCash\ /home/blah/.vim\ /home/blah/my-bookmarks.html # We do the doMakeTar as many times as we want to make a logical ordering of # files. # backup the rest of my stuff doMakeTar $scriptTempDirectory/blah-documents-$date.tar /home/blah/Documents/ # doMakeFinalTarball makes the .tar.gz file which is actually backed up -- if # you forget this step, you won't get anything in the resulting backup file! # With that said, it takes any number of arguments and all of these arguments # are the .tar files created with the doMakeTar command above. So, basically, # just make a list of your resulting .tar files here, like this: # The final backup tarball is made up of the otherstuff and the homedirectory. doMakeFinalTarball $scriptTempDirectory/blah-homedirectory-$date.tar\ $scriptTempDirectory/blah-documents-$date.tar
After you finish the laughably easy configuration and scripting, you just run pebs. The results look like this:
Pug's Extensible Backup System (Version 0.25) This software is released under the GNU GPL Version 2 or later. [*] Executing /root/backup_scripts/individual_scripts/system_files.inc.sh [*] Creating tar backup to /tmp/BackupLocation/system_files/system-etc-Sat.tar [*] Making final tarball for this backup set… [*] Gzipping tar backups to /tmp/BackupLocation/Results/system_files.tar.gz [?] Removing temp files for system_files ================================================ [*] Making final backup tar for this run. [*] Creating tar backup to /tmp/BackupLocation/Backup-resmiranda-Sat.tar [?] Encrypting using jcjones@ufl.edu’s public key… [?] Transmitting, total size: 8.5M [?] Verifying hashes… [?] Local Hash: 3f427e745d0c9f847ee0c50d9816316a - Remote Hash: 3f427e745d0c9f847ee0c50d9816316a [*] Hashes are identical. Good transfer. [*] All Done!
No comments yet. Be the first.
Leave a reply