[LBo] howto generate file names with dates for TAR backups?

Andrew Henry adhenry at bredband.net
Wed Feb 7 20:22:32 CET 2007


>export FN=$(date +%Y-%m-%d-%a-%Hh%M.tgz)

Ok thanks a lot for that tip, it worked a treat, but now the next issue...

I want to autogenerate a logfile for the backup and i've already made an
attempt at supplying a few things, but how do I get the CPU info,
architecture and Linux version to be sent to the logfile?

For CPU, I tried grep model\ name /proc/cpuinfo >> README but it does
not work.  I also tried a pipe, but I do not think I am using it correctly:

grep model\ name /proc/cpuinfo | echo - README

I tried similar techniques with uname -r for the system version and
$arch for architecture, but im obviosly missing something.

Here is my nearly complete script so you can see what I'm trying to attempt:

#!/bin/sh
## remove previous snar files as performing a new level 0 backup
## root must run this script to be able to create the /var/log/ files

## depending on which level is being backuped up, comment out the
relevant lines below

## Level-0 header
rm -f /var/log/snar*

## Level-1 header
# cp /var/log/snar /var/log/snar-1

## Level-2 header
# cp -u /var/log/snar /var/log/snar-1
# cp /var/log/snar-1 /var/log/snar-2

## environment variables must be changed for different incremental levels
export LVL=backup-lvl0-yearly
export STAMP=$(date +%a-week%V-%Y%m%d-%Hh%M-%Z)
export TARGET_DIR=/media/ieee1394disk/backups
export SNARFILE=/var/log/snar


## important:
## cannot use --exclude as this breaks incrementals (fixed in tar 1.16).
## cannot use -z to gzip within tar command as this is unsupported with
incrementals.
## need to run as root in case there are other users in /home

echo "Archiving files..."
tar -cvPWf \
    $TARGET_DIR/$LVL-$STAMP.tar \
    --listed-incremental $SNARFILE \
        /home/andrew/ \
        '/media/hda2/Documents and Settings/All Users/Documents/My
Pictures/' \
        '/media/hda2/Documents and Settings/TME/My Documents/' \
        '/media/hda2/Documents and Settings/TME/Application Data/GnuPG/' \
        '/media/hda2/Documents and Settings/TME/Application Data/Mozilla/' \
        '/media/hda2/Documents and Settings/TME/Application
Data/Thunderbird/' \
            > $TARGET_DIR/$LVL-$STAMP.log

## make a backup of the Master Boot Record
dd if=/dev/hda of=$TARGET_DIR/$LVL-$STAMP.MBR bs=512 count=1

## to restore MBR manually...
#dd if=MBR-backup of=/dev/hda bs=512 count=1

echo "Compressing archive with gzip..."
gzip -v $TARGET_DIR/$LVL-$STAMP.tar

## make me the owner
chown andrew:andrew $TARGET_DIR/$LVL-$STAMP.*

## encrypt the tarball
echo "Encrypting archive with GnuPG..."
gpg -r adhenry at bredband.net -o $TARGET_DIR/$LVL-$STAMP.tar.gz.gpg -ve
$TARGET_DIR/$LVL-$STAMP.tar.gz

## remove tgz file as GPG doesn't do this automatically
rm -f $TARGET_DIR/$LVL-$STAMP.tar.gz

## root gpg'd file so change ownership to me
chown andrew:andrew $TARGET_DIR/$LVL-$STAMP.*

## use split to split a multiGIG file into manageable 2GB parts for
burning to DVD
#echo "Splitting encrypted archive into 2GB chunks..."
#cd $TARGET_DIR
#split -b 2147483648 $TARGET_DIR/$LVL-$STAMP.tar.gz.gpg
#chown andrew:andrew $TARGET_DIR/xa*

## autocreate README for backup
echo "backup-type       =  $LVL" > $TARGET_DIR/$LVL-$STAMP.README
echo "backup-date       =  $STAMP" >> $TARGET_DIR/$LVL-$STAMP.README
echo "backup-dirs       =  /home/andrew, Windows Users" >>
$TARGET_DIR/$LVL-$STAMP.README
echo "backup-file-name  =  $LVL-$STAMP.tar.gz.gpg" >>
$TARGET_DIR/$LVL-$STAMP.README
echo " " >> $TARGET_DIR/$LVL-$STAMP.README
echo "Backup performed on Ubuntu 6.06 amd64 with following utilities:"
>> $TARGET_DIR/$LVL-$STAMP.README
echo " " >> $TARGET_DIR/$LVL-$STAMP.README
tar --version >> $TARGET_DIR/$LVL-$STAMP.README
echo " " >> $TARGET_DIR/$LVL-$STAMP.README
gzip --version >> $TARGET_DIR/$LVL-$STAMP.README
echo " " >> $TARGET_DIR/$LVL-$STAMP.README
gpg --version >> $TARGET_DIR/$LVL-$STAMP.README


-- 
GnuPG Key ID: ECB18ABA
Fingerprint:  FDF3 91FC F5BC 1164 E217  315E 337E 219B ECB1 8ABA


More information about the QnA mailing list