I want to write the equivalent of DOS batch files for simplifying backups using tar, and doing a few other things. How is this done in Linux using ver 7.3? Harry G
On Tuesday 05 February 2002 19:59, Harry G wrote:
I want to write the equivalent of DOS batch files for simplifying backups using tar, and doing a few other things. How is this done in Linux using
check out the Advanced Bash Scripting HowTo, probably located here (on a standard SuSE installation: /usr/share/doc/howto/en/html/Adv-Bash-Scr-HOWTO those shellscripts are a very easy way to getting stuff done automagically... but they're pretty powerful as well... Hansen -- Powered by SuSE 7.3 - Linux 2.4.10-4GB KDE 2.2.1 - KMail 1.3.1
OK. Now for a really dumb question. Do I write the scripts in an editor, or from the command line or what? In DOS, you used an editor and named it with an .bat extension. I would suspect you would do some sort of chmod ??? filename, then run it with a ./file.sh? Harry G On Tuesday February 05 2002 02:12 pm, you interfaced in analog form:
On Tuesday 05 February 2002 19:59, Harry G wrote:
I want to write the equivalent of DOS batch files for simplifying backups using tar, and doing a few other things. How is this done in Linux using
check out the Advanced Bash Scripting HowTo, probably located here (on a standard SuSE installation: /usr/share/doc/howto/en/html/Adv-Bash-Scr-HOWTO
those shellscripts are a very easy way to getting stuff done automagically... but they're pretty powerful as well...
Hansen
On Tue, 5 Feb 2002 17:31:02 -0500 Harry G <harrycg@earthlink.net> wrote:
OK. Now for a really dumb question. Do I write the scripts in an editor, or from the command line or what? In DOS, you used an editor and named it with an .bat extension. I would suspect you would do some sort of chmod ??? filename, then run it with a ./file.sh?
You don't need any extension in linux, just chmod the file to 700, and it will execute. chmod 700 myscript You can put the first line #!/bin/sh to make it easier for the shell to know it's a script; but a shell script will run without that #!/bin/sh. -- $|=1;while(1){print pack("h*",'75861647f302d4560275f6272797f3');sleep(1); for(1..16){for(8,32,8,7){print chr($_);}select(undef,undef,undef,.05);}}
On Tuesday 05 February 2002 21:10, Harry G wrote:
OK. Now for a really dumb question.
never... we have all started with DOS, I guess... :)
Do I write the scripts in an editor, or from the command line or what?
well, after all you need your script in some kind of file... wouldn't make sense to write it new each time... :) ...so I'd use an editor... you could actually do it from the commandline, but that would be very tedious work...
In DOS, you used an editor and named it with an .bat extension. I would suspect you would do some sort of chmod ??? filename, then run it with a ./file.sh?
Linux doesn't care about file extensions, so you could name it as you'd like, but the first line in the file should be (for a shell-script) #!/bin/sh it tells the system what interpreter to use... it'll run w/o that, I think... when you're done, you make the script executable (e.g. if you want it to be usable by everybody: chmod ugo+x filename) you can then run it as you suggested, but you might also copy it to /usr/bin or some other dir in the path and be able to use it like any other command... besides that, they really work like batch-files... just put commands in them and they'll be executed after another... but those scripts are a lot more powerful... you can program loops and if-clauses, you can even construct graphical menus... Hansen
Harry G
On Tuesday February 05 2002 02:12 pm, you interfaced in analog form:
On Tuesday 05 February 2002 19:59, Harry G wrote:
I want to write the equivalent of DOS batch files for simplifying backups using tar, and doing a few other things. How is this done in Linux using
check out the Advanced Bash Scripting HowTo, probably located here (on a standard SuSE installation: /usr/share/doc/howto/en/html/Adv-Bash-Scr-HOWTO
those shellscripts are a very easy way to getting stuff done automagically... but they're pretty powerful as well...
Hansen
-- Powered by SuSE 7.3 - Linux 2.4.10-4GB KDE 2.2.1 - KMail 1.3.1
Harry G wrote:
OK. Now for a really dumb question. Do I write the scripts in an editor, or from the command line or what? In DOS, you used an editor and named it with an .bat extension. I would suspect you would do some sort of chmod ??? filename, then run it with a ./file.sh?
Hi Harry, I came across a script a while ago which I've been using ever since for my backups. ------------------------------------------------------------------------------ #!/bin/bash # Incremental backup of $DIR # To make a master backup, just delete the snapshot file # NB, the exclude file must not include any blank lines - not even a final empty line. # Implement the curly bracket wrapper below if you want to log # all this (and not see anything directly on the screen). #{ [ $# -eq 0 ] && exit 0 DIR=$1 BUTYPE=Incr # if $DIR/.tar.exclude doesn't exist we need to make it, else tar will refuse to run. # assuming write permission here [ -e $DIR/.tar.exclude ] || touch $DIR/.tar.exclude # if this file exists - and is NOT EMPTY (-s) - then is a Main backup [ -s $DIR/.tar.snapshot ] || BUTYPE=Full tar cvjf \ "/common/backup/`date +%Y%m%d`-$BUTYPE-$DIR.tar.bz2" -X $DIR/.tar.exclude -g $DIR/.tar.snapshot $DIR # } >> ~/backup.log 2>&1 ------------------------------------------------------------------------------- It uses the listed incremental options of tar to make full or incremental backups of a directory dependant on there being a file called .tar.snapshop in the directory of the one you are backing up. To use, save the bit between the lines to a file called bu, chmod to be executable. Change to the parent directory of the one you want to backup and type bu directory_name_to_backup. This will create the backup file in /common/backup/filename_of_backup, change the path as required. The first time this is run it will make a full backup, subsequent times will make an incremental backup. To make another full backup, delete the file .tar.snapshot from the directory. I actually run this script from another script which is executed by cron in the early hours, which basically cd's to a series of directories and performs the bu script on subdirectories. The .tar.exclude file can be used to exclude directories from being backed up, useful for excluding internet caches, etc. regards Steve
participants (4)
-
Harry G
-
Johannes Liedtke
-
Stephen Allewell
-
zentara