System :: filetool.sh hack



Hi all,

I finaly did what I threatened to do and hacked filetool.sh so I can backup using the default backup.tar.gz or backup_(name).tar.gz from the command line.  These are the changes I made.

In Beaver I did a replace of all instances of backup.tar.gz with $BACKUPNAME.

At line 24 I inserted
Code Sample
if [ -z $4 ]; then
 BACKUPNAME="backup.tar.gz"
else
 BACKUPNAME="backup_$4.tar.gz"
fi


line 97 was changed to reflect the filename in addition to the device
Code Sample
   echo -n "${BLUE}Backing up files to ${MAGENTA}$MOUNTPOINT/$BACKUPNAME ${BLUE}mounted on ${MAGENTA}/dev/$DEVICE ${NORMAL}"

and the same change to line 125.

Changed the instructions on line 13 to reflect this change and the other command line options.
Code Sample
 echo "Usage: filetool.sh {backup|restore [null]|[non-null] device backup_name(changes file name to backup_(backup_name).tar.gz from backup.tar.gz}"

Code Sample
sudo filetool.sh backup z hdd4 project01_00
creates a backup to hdd4 named backup_project01_00.tar.gz

The only glitch I've found is argument $2 has to be non-null and I guess a space doesn't work.  Therefore I get the colorful line with the spinning thingy instead of tar being verbose. Perhaps an or in the if checking for $2 eq "verbose" (sure thats the wrong syntax) in addition to null.  I havn't tested it with blowfish. I am using DSL 4.4

I am using this to backup parts of my DSL/Apache web server hard drive install named by project and date stamped so I can roll back to an earlier version when something experimental fails.  

Thanks all
:D

Cron job
"sudo filetool.sh backup z hdd4 project_$(date +%F)"

Makes the backup as backup_project_2008-10-09.tar.gz, if used today.

$(date +%Y_%m_%d) if you prefer
backup_project_2008_10_09.tar.gz instead :P

Also, a space won't work for $2 because an unescaped space is treated as a whitespace. You could try
sudo filetool.sh backup \  hdd4 project_$(date +%F)

Note, two spaces after \

or
sudo filetool.sh backup " " hdd4 project_$(date +%F)

Hi chaostic

Quote
Also, a space won't work for $2 because an unescaped space is treated as a whitespace. You could try
sudo filetool.sh backup \  hdd4 project_$(date +%F)

Note, two spaces after \

or
sudo filetool.sh backup " " hdd4 project_$(date +%F)


Ok, note the last part of my signature (I must have had one of those).  If a character doen't work put a \, if a string doesn't work put it in quotes.  As long as I have been writing in PERL I should have known better.

The example was just by way of illustration of the functionality.  I hand name most old archive versions because I may not make a copy to roll back to until I am doing something thay may go completly wrong so I may call todays backup 2008_june.  But an automatic date stamp as an option wouldn't be hard. ???
(In fact I'm gonna give that a quick go right now)

Thanks

Ok, the inserted code becomes
Code Sample
if [ -n $5 ]; then
 if [ -z $4 ]; then
   BACKUPNAME="backup_$(date +%Y_%m_%d).tar.gz"
 else
   BACKUPNAME="backup_$4_$(date +%Y_%m_%d).tar.gz"
 fi
else
 if [ -z $4 ]; then
   BACKUPNAME="backup.tar.gz"
 else
   BACKUPNAME="backup_$4.tar.gz"
 fi
fi


And it needed "" instead of " " because -z is looking for a edit:* "null string" not a space.  I guess I was for some reason thinking whitespace could be a deliminator :p

*edit: null is the ASCII character 0 and -z looks for a string of 0 length or a "null string" not a null

Next Page...
original here.