News:

Facebook killed the radio star. And by radio star, I mean the premise of distributed forums around the internet. And that got got by Instagram/SnapChat. And that got got by TikTok. Where the fuck is the internet we once knew?

Main Menu

*NIX backup script

Started by chuck, December 31, 2006, 01:13:33 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

chuck

I wrote this yesterday and I use it from a remote machine to backup my mail and stuff.

First, to make the ssh login quick and easy:

ssh-keygen -t rsa
scp .ssh/id_rsa.pub root@MailServer.local:.ssh/authorized_keys


Then, I run:

mkdir ~/baks


And after that, I save this script somewhere and add it to my crontab:

#!/bin/sh
# Machine to login to. This script will do ssh $USER@$MACHINE
USER="root"
MACHINE="MailServer.local"

# Remote dir's to backup
LIST="/home /etc /var/lib/dpkg"

BACKDIR="$HOME/baks"

###############################
# No more configuration options
YEAR=`date "+%Y"`
MONTH=`date "+%B"`
DAY=`date "+%d"`

BACKDIR="$BACKDIR/$MACHINE/"

for d in $LIST; do
        if ! [ -d $BACKDIR ]; then
                mkdir $BACKDIR
        fi

        if ! [ -d $BACKDIR/$YEAR ]; then
                mkdir $BACKDIR/$YEAR
        fi

        if ! [ -d $BACKDIR/$YEAR/$MONTH ]; then
                mkdir $BACKDIR/$YEAR/$MONTH
        fi

        if ! [ -d $BACKDIR/$YEAR/$MONTH/$DAY ]; then
                mkdir $BACKDIR/$YEAR/$MONTH/$DAY
        fi

        FILENAME=`echo $d | sed 's/\///'`
        FILENAME=`echo $FILENAME | sed 's/\//./g'`

        ssh $USER@$MACHINE "tar zcpf - $d" | cat > $BACKDIR/$YEAR/$MONTH/$DAY/$FILENAME.tgz
done


When the script runs, it creates the directory's for the machine, year, month, and day. It then runs tar on the remote machine and cat's it to a tgz file.

Just posting this here so it may help someone :)
Chucks Blog
JavaOp2 Plugins

Quote
Error, keyboard not connected. Press F1 to continue.