You are not logged in.
Ok I have a backup script made but i need to have a small part that checks whether there is a /var/backups and /var/backups/work and if there isnt create them.. Also i need to have it where the script creates a file filename.tar.bz2 and move its to /var/backups/packagename-Date.tar.bz2
but i need to know how to make it generate the date based on the os somehow like the clock if it has a date im not sure... But you should understand what i mean... The script is in bash well i think its bash if it has #! /bin/bash at the top so plz help..
Offline
O i would also like to make this a package so if anyone knows how to make /sbin/files that would be great so that way it can execute that script which will reside in a directory that maybe you can tell me where it should be placed... If you understand what i mean.. If this isnt how it works then could please someone just help me..
Offline
Any suggestions with this following script would be nice
New version below..
Offline
anyone?
Offline
Use backticks, e.g.
# touch `date +arc-section-%F.tar.bz2`
To make your script more portable you should use #!/bin/sh instead of /bin/bash.
For a good bash scripting guide see http://www.tldp.org/LDP/abs/html
You''ll find info about tests and much more there.
I'm not sure what you mean with installing the script, but simply moving it to /usr/sbin and making it executable should be enough.
(And don't be so impatient...)
Offline
O ok that will allow me to just run arch-hd-backup right? thanks..
Offline
where would i do the touch part how would i do that..
Offline
Can you possibly tell me how to have it ask the differnt ways to tar it lets say it asks this
Do you want sepeate files? [y/n] y
Do you want /home [y/n] y Then that makes the script tar /home seperatly
Do you want /boot [y/n] n That makes this question be asked
Should it be included with / ? [y/n] y
Can you explain that... If no i guess ill just read that whole thing.. Its just i need this for my script.. It will probably be a big hit then because it will back ur entire hd up... IThen later ill have it where its like filename -R which would make it ask some stuff about restoring it to a specified partition and mount stuff like that.... Is that possible with shell scripting or is that c or something?
Offline
New version below
Offline
Offline
Anyone willing to try it its in its last beta stage.. Just needs to be tested.. So anyone that would host it for people to download that would be nice also.. Its very small 3kb... But anyways thx in advance..
Offline
New version available..
Offline
probably the syntactical error on that line..
elif [ "$action" ...
should probably be
if [ "$action"
I use bash for my scripting, so I dont offhand recall what sh uses for if statements..
"Be conservative in what you send; be liberal in what you accept." -- Postel's Law
"tacos" -- Cactus' Law
"t̥͍͎̪̪͗a̴̻̩͈͚ͨc̠o̩̙͈ͫͅs͙͎̙͊ ͔͇̫̜t͎̳̀a̜̞̗ͩc̗͍͚o̲̯̿s̖̣̤̙͌ ̖̜̈ț̰̫͓ạ̪͖̳c̲͎͕̰̯̃̈o͉ͅs̪ͪ ̜̻̖̜͕" -- -̖͚̫̙̓-̺̠͇ͤ̃ ̜̪̜ͯZ͔̗̭̞ͪA̝͈̙͖̩L͉̠̺͓G̙̞̦͖O̳̗͍
Offline
well sh and bash is almost the same isnt? I was told to do sh instead of bash.. But ah it is correct i had another error i fixed it now and now im changing the script alot.. Less questions... More arguments (ie hdbackup -verbose)
Offline
i need to have a small part that checks whether there is a /var/backups and /var/backups/work and if there isnt create them
mkdir -p /var/backups/work will do this - it will create the directory (and its parents if required), and not give an error if it already exists.
BTW, you should consider splitting your script up into functions. It'd make it a lot easier to read and understand.
- olly
Offline
Rewritten
Offline
And i get alot of these
/usr/bin/hdbackup: line 83: [: =: unary operator expected
/usr/bin/hdbackup: line 111: [: =: unary operator expected
How to fix that?
Offline
/usr/bin/hdbackup: line 83: [: =: unary operator expected
/usr/bin/hdbackup: line 111: [: =: unary operator expected
These are from lines like
if [ $1 = -vs ]; then
Think what happens if $1 is undefined - there's nothing on the left-hand of the test, which is giving the error.
If you testing args it's more common to use case ... esac.
Your script would be a lot more readable if you got rid of all the tests to detect files created and just tested $? instead. And dump the verbose error message if it fails - you'll have got an error message from the command that went wrong.
- olly
Offline
The error messages are so that you know it failed and it doesnt keep going... Im going to make it where you input the directories you want and all later if i can get some help on how to do it.. Really i need help on rewriting the script to make it cleaner... Then again i just started last night (24 hours ago)
Offline
The error messages are so that you know it failed and it doesnt keep going
I'm not suggesting you get rid of the tests. Just do them a bit less verbosely.
Instead of...
$HTARCN
if [ -x "$DIR2/$HNM" ]; then #Checks to see if the file was created to make sure its there.
$E "$HDIR" backup completed.
$HMV
else
$E "$HDIR" backup failed. Exiting and please retry.; exit 1
fi
...you can just do...
$HTARCN || exit 1
$HMV
- olly
Offline
Meant to say i need to know how to check if they were created if not create them and then check if they were created or it iwll exit...
Offline
That really does it? I though youd have to do an if then thing to check if its there...
Offline
Rewritten with suggestions by olly-bh so olly-bh is this what you say it should look like...
#!/bin/sh
# This script is becoming an advanced backup script.. Any suggestions are welcome.. Email to iotc247@hotmail.com
# Contributed by Alex Heck (iotc247)
# Starting variables
# Echo variables
E=echo
# End echo variables
# Begin Directory Variables
ADIR=/
HDIR=/home
MDIR=/
BDIR=/boot
DIR1=/var/backups
DIR2=/var/backups/work
# End Directory variables
# Name variables
AN=`date +arch-all-%F.tar.bz2`
MN=`date +arch-main-%F.tar.bz2`
BN=`date +arch-boot-%F.tar.bz2`
#if [ $1 = --help ]; then
#echo "hdbackup [-vso] [-hso]"
#echo "hdbackup -vs This is verbose mode with seperate partition backups."
#echo " This means that you will get one for /home one for /boot and so on.."
#echo "hdbackup -vo This is verbose mode with only one the / directory and everything in it except for /proc"
#echo
#echo
#echo
#echo "hdbackup -hs This is hidden mode with seperate partition backups."
#echo " This means that you will get one for /home one for /boot and so on.."
#echo "hdbackup -ho This is hidden mode with only one the / directory and everything in it except for /proc"
#exit 0
#fi
HN=`date +arch-home-%F.tar.bz2`
# End name variables
# Move Name variables
ANM=arch-all-*.tar.bz2
MNM=arch-main-*.tar.bz2
BNM=arch-boot-*.tar.bz2
HNM=arch-home-*.tar.bz2
# End name variables
# Begin Taring Variables
# Verbose
ATARC="tar -jcvf $DIR2/$AN $ADIR --exclude=$DIR1/# --exclude=$MNT/*"
MTARC="tar -jcvf $DIR2/$MN $MDIR --exclude=$BDIR/* --exclude=$HDIR/* --exclude=$DIR1/* --exclude=/mnt/*"
BTARC="tar -jcvf $DIR2/$BN $BDIR"
HTARC="tar -jcvf $DIR2/$HN $HDIR"
# Non-Verbose
ATARCN="tar -jcf $DIR2/$AN $ADIR --exclude=$DIR1/# --exclude=$MNT/*"
MTARCN="tar -jcf $DIR2/$MN $MDIR --exclude=$BDIR/* --exclude=$HDIR/* --exclude=$DIR1/* --exclude=/mnt/*"
BTARCN="tar -jcf $DIR2/$BN $BDIR"
HTARCN="tar -jcf $DIR2/$HN $HDIR"
# End Taring Variables
# Moving Variables
AMV="mv $DIR2/$ANM $DIR1/"
MMV="mv $DIR2/$MNM $DIR1/"
HMV="mv $DIR2/$HNM $DIR1/"
BMV="mv $DIR2/$BNM $DIR1/"
ROOT_UID=0
E_NOTROOT=67
# Finished with Variables
# Check to see if you are root
if [ "$UID" -ne "$ROOT_UID" ]
then
$E "Must be root to run this script."
exit $E_NOTROOT # Your not root so its gonna quit
fi
# Done checking for root access
if [ -x "$DIR1" ]; then # Checking for Dir1
:
else
mkdir "$DIR1"
fi
if [ -x "$DIR2" ]; then # Checking for Dir2
:
else
mkdir $DIR2
fi
cd $DIR2
# Begin verbose actions
if [ $1 = -vs ]; then
$E Starting "$MDIR" backup
$MTARC || $ $E "Baclup failed"; exit 1
$E Backup completed.
$MMV
$E Starting "$HDIR" backup
$HTARC || $ $E "Baclup failed"; exit 1
$HMV; $E Backup completed
$E Beginning "$BDIR" backup
$BTARC || $ $E "Baclup failed"; exit 1
$BMV; rm $DIR2; $E Backup completed. Finished; exit 0
fi
if [ $1 = -vo ]; then
$E "Starting full backup"
$ATARC || $ $E "Baclup failed"; exit 1
$AMV; rm $DIR2; $E Backup completed. Finished; exit 0
fi
# Ending verbose process
# Begin non-verbose process
if [ $1 = -hs ]; then
$E Starting "$MDIR" backup
$MTARCN || $ $E "Baclup failed"; exit 1
$MMV; $E Backup completed
$E Starting "$HDIR" backup
$HTARCN || $ $E "Baclup failed"; exit 1
$E Beginning "$BDIR" backup
$BTARCN || $ $E "Baclup failed"; exit 1
$EMV; rm $DIR2; $E Backup completed. Finished; exit 0
fi
if [ $1 = -ho ]; then
$E "Starting full backup"
$ATARCN || $ $E "Baclup failed"; exit 1
$AMV; rm $DIR2; $E Backup completed. Finished; exit 0
fi
# End non-verbose process
# normal output for plain hdbackup
echo "hdbackup [-vso] [-hso]"
echo "hdbackup -vs This is verbose mode with seperate partition backups."
echo " This means that you will get one for /home one for /boot and so on.."
echo "hdbackup -vo sThis is verbose mode with only one the / directory and"
echo " everything in it except for /proc"
echo
echo
echo
echo "hdbackup -hs This is hidden mode with seperate partition backups."
echo " This means that you will get one for /home one for /boot and so on.."
echo "hdbackup -ho This is hidden mode with only one the / directory and"
echo " everything in it except for /proc"
exit 0
Offline
How would i make this use getopts instead of the if [ $1 = -c ]; then stuff.
Offline
search, you scallawag!
Offline