Linux, programming, computers and life

June 30, 2007

Do not say “It won’t happen to me” and always make backups

Filed under: programming, linux

I’m the millionth person to say this - you have to, you need, you must backup. Backup is not only protection against hardware failures, it’s also protection against user error. Backup is very easy to setup nowdays. It’s possible to have some online storage and backup there, backup from one physical hard drive to another, to flash memory stick or even to email some files to gmail.
The last reason i had to restore was the following command: gpg -d passwords.txt.gpg > passwords.txt.gpg - redirection first truncates the destination file - so i was left without my passwords collection :) .
My backup policy is to backup my home folder - all flies smaller than 20MB and the /etc directory to another physical hard disk twice a week using sbackup. Recently i added a small script which sends email with several attached (small) files to my gmail account. It’s being run daily by cron daemon.
Here’s the script i use for emails:

#! /bin/bash

# tar gz files:
DATE=`date +%F_%T`
OUT_FILE=”/tmp/${DATE}.tar.bz2″
BACKUP_FILES=”/home/some_path/*.txt”
BACKUP_EMAIL=”my_gmail_email@gmail.com”

tar cvfj “$OUT_FILE” $BACKUP_FILES
trap “{ rm -f “$OUT_FILE” ; exit 255; }” EXIT

FILE_SIZE=`\ls -lh “$OUT_FILE” | cut -d ‘ ‘ -f 5`
SUBJECT=”backup of `echo $BACKUP_FILES | wc -w` files ($FILE_SIZE) at $DATE”
echo “`echo ${BACKUP_FILES} | tr ‘ ‘ ‘\n’`” | mutt -a “$OUT_FILE” “$BACKUP_EMAIL” -s “$SUBJECT”

rm “$OUT_FILE”


It uses mutt for sending email with attachments.

Technorati Tags: , , ,

Get free blog up and running in minutes with Blogsome
Theme designed by Gary Rogers