[LBo] howto generate file names with dates for TAR backups?
Andrew Henry
adhenry at bredband.net
Wed Feb 7 22:10:38 CET 2007
Chris F.A. Johnson wrote:
> On Wed, 7 Feb 2007, Andrew Henry wrote:
>
>>> 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:
>
> What does "does not work" mean? What, exactly, *does* happen?
>
> What happens when you give the command without redirection?
>
> Does it work at the command line?
>
> Did you try:
>
> grep 'model name' /proc/cpuinfo
>
>> grep model\ name /proc/cpuinfo | echo - README
>
> echo prints its arguments; it does not read stdin.
>
>> I tried similar techniques with uname -r for the system version and
>> $arch for architecture, but im obviosly missing something.
>
> Again, please describe exactly what you used and what happens.
>
>> 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
>
> When posting a script to a mailing list or newsgroup, please ensure
> that you post a valid script. If your mail or news client wraps
> lines, keep the lines short to prevent that (or get a better
> client).
>
>> ## 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
>
> YOu don't need to export variables unless thay are needed by a
> script you are calling from *this* script.
>
>> ## 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/' \
>
> See above regarding word wrap.
>
>> '/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/' \
>
> Ditto
>
>> > $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
>
> Your script will be easier to read if you group you commands and use
> a single redirection:
>
> {
> echo "backup-type = $LVL"
> echo "backup-date = $STAMP"
> echo "backup-dirs = /home/andrew, Windows Users"
> echo "backup-file-name = $LVL-$STAMP.tar.gz.gpg"
> echo " "
> echo "Backup performed on Ubuntu 6.06 amd64 with following utilities:"
> echo " "
> tar --version
> echo " "
> gzip --version
> echo " "
> gpg --version
> } > $TARGET_DIR/$LVL-$STAMP.README
>
Hi Chris,
Thanks for the info about using braces when echo'ing text to a file, I
didn't know you could do that. Sorry all about the word wrap thing. I
use Thunderbird. Is there a better way to attach a script? Should I
attach it as a file instead of inline?
Regarding the pipes and redirectors, I don't know what I was doing
wrong, but it now seems to work:
andrew at redwood:/proc$ grep model\ name /proc/cpuinfo
model name : AMD Turion(tm) 64 Mobile Technology ML-28
andrew at redwood:/proc$ grep model\ name /proc/cpuinfo >> $HOME/readme
andrew at redwood:/proc$ cat $HOME/readme
model name : AMD Turion(tm) 64 Mobile Technology ML-28
andrew at redwood:/proc$
--andrew
--
GnuPG Key ID: ECB18ABA
Fingerprint: FDF3 91FC F5BC 1164 E217 315E 337E 219B ECB1 8ABA
More information about the QnA
mailing list