You are not logged in.

#1 2012-08-25 19:52:12

Riptawr
Member
Registered: 2011-09-14
Posts: 18

incremential backup script, $TIMESTAMP does not work as intended.

I found this old backup script and after testing some testing found a strange bug.

On most of the servers it worked fine except on one, where following line:

 /bin/tar -zcf $BACKUP_DIR/current\_$TIMESTAMP.tar.gz * 

would change after execution to the value of $TIMESTAMP instead:

  /bin/tar -zcf $BACKUP_DIR/current\_/bin/tar -zcf $BACKUP_DIR/current\_$Sat 25 Aug 2012 11:41:04 PM MSK.tar.gz * 

i never saw a script to change its own source code so far, so i won't take responsibility if it becomes sentient and starts to nuke things..

#########################################################################
#!/bin/sh                                                               #
# cron: 0 3 * * * root /root/adm/backup.sh                              #
# Script for making backups with timestamp into specific directory      #
#                                                                       #
#### Settings ###########################################################
ETC_DIR=/root/adm/backup.sh
#BACKUP_DIR=/backupsrv
BACKUP_DIR=/backup

FILES_SRC=$ETC_DIR/backup_src.lst # list of dirs to back up
INCLUDE_FILES_PATTERN=$ETC_DIR/backup_include.lst 
EXCLUDE_FILES_PATTERN=$ETC_DIR/backup_exclude.lst # what filetypes to exclude
echo "$INCLUDE_FILES_PATTERN"
TIMESTAMP=`date '+%Y%m%d-%H%M%S'`
DAY=`date '+%d'`

FULL_BACKUP_DIR=$BACKUP_DIR/current
INC_BACKUP_DIR=$BACKUP_DIR/$DAY\_$TIMESTAMP

#### Begin ###############################################################
rm -f -R $BACKUP_DIR/$DAY\_*

#/bin/nice -n 10 
rm $BACKUP_DIR/installed_packages.lst # arch linux only
pacman -Q >> /$BACKUP_DIR/installed_packages.lst  #arch linux only
/usr/bin/rsync -r --force --ignore-errors --delete \
--delete-excluded \
  -av -L  \
  --backup --backup-dir=$INC_BACKUP_DIR \
  --exclude-from=$EXCLUDE_FILES_PATTERN \
  --include-from=$INCLUDE_FILES_PATTERN \
  --files-from=$FILES_SRC \
  / $FULL_BACKUP_DIR

rm -f $BACKUP_DIR/current\_*.tar.gz

cd $BACKUP_DIR
#/bin/nice -n 10 
/bin/tar -zcf $BACKUP_DIR/current\_$TIMESTAMP.tar.gz * 

Last edited by Riptawr (2012-08-25 19:54:46)

Offline

#2 2012-08-26 12:22:12

fturco
Member
Registered: 2010-07-12
Posts: 40

Re: incremential backup script, $TIMESTAMP does not work as intended.

I'm not a bash expert, and I don't know the answer to your question, but why you use a backslash followed by an underscore multiple times? I've never seen that syntax...

Offline

#3 2012-08-26 20:11:14

Riptawr
Member
Registered: 2011-09-14
Posts: 18

Re: incremential backup script, $TIMESTAMP does not work as intended.

its backslash-escape, same as quoting and easyer to write as quote in quotes in quotes and so on. The underscore is just naming convention, gives me filename_$Timestamp.tar.gz

Offline

#4 2012-08-27 00:14:52

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,222
Website

Re: incremential backup script, $TIMESTAMP does not work as intended.

I've never had to escape underslash before; why are you doing that?

Have you tried enclosing the variable name with curly braces to make sure there's no bash modifiers going on?

${TIMESTAMP}

Offline

Board footer

Powered by FluxBB