Ask Donneker
Google
Klarmachen zum Ändern! Piratenpartei

projects - shell-backup-scripts

Backup Shell Scripts for bash or ksh88, UNIX and Linux:
backup shell scripts by Stefan Hummert
more about the shell backup script creator

this scripts can be used to backup or sync your directories and files recursive




shell backup scripts
this scripts can be used to backup or sync your directories and files recursive


created by Stefan Hummert
last modified 18.07.2008 by Stefan Hummert

GNU GPL

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 3 of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

Text version: http://www.gnu.org/licenses/gpl.txt
HTML version: http://www.gnu.org/licenses/gpl.html

free downloads:
bash backup scripts
ksh backup scripts

See more about how you could backup your UNIX / Linux system here Automate backups on Linux
#!/bin/bash

MYBCKP=$(cat backup.conf)

{
echo " --- Logdate --- $(date)"
echo " --- Logdate --- $(date)" >&2

cat /dev/null >$MYBCKP/backup.actual
touch $MYBCKP/backup.actual

BACKUP_SOURCE=( $(cat $MYBCKP/mybackup.source) )
BACKUP_TARGET=( $(cat $MYBCKP/mybackup.target) )

if [[ ${#BACKUP_SOURCE[*]} -ne ${#BACKUP_TARGET[*]} ]]; then
    echo "BACKUP_SOURCE != BACKUP_TARGET"
    exit 1
fi

anzDir=${#BACKUP_SOURCE[*]}
i=0
while ((i < anzDir))
do
    echo "Saving source ${BACKUP_SOURCE[$i]} to target ${BACKUP_TARGET[$i]}"
    cd ${BACKUP_SOURCE[$i]}
    echo "Directory: $PWD"
    find . -newer $MYBCKP/backup.date -type d -print -exec $MYBCKP/mymkdir.sh ${BACKUP_TARGET[$i]}/{} \;
    find . -newer $MYBCKP/backup.date -type f -print -exec $MYBCKP/mycopy.sh {} ${BACKUP_TARGET[$i]}/{} \;
    let i=$i+1
done

mv $MYBCKP/backup.actual $MYBCKP/backup.date

} >>$MYBCKP/backup.log 2>>$MYBCKP/backup.err

how to use - README instructions, please read before you use the scripts!:

Simple commandline backup/synchronization script 
written by Stefan Hummert
Version: 1.00
visit http://donneker.de/projects/shell-backup-scripts/
see also bash scripting guide http://www.donneker.de/HowTo/A-Short-Documentation-Reference-Manuals/bash/

This software is free licenced under the GPL - for more info see
http://www.gnu.org/licenses/gpl.txt

What is the purpose of this tool?
The purpose of this scripts is to backup/synchronise two directories that should contain
the same files. The scripts does this recursive through directories. Also it only synchronise the
delta, which is defined by date. 
So if you run this script first time, you should set the date of the backup.date file
according to 01.01.1970 to get all files synchronised. The next time the script runs, it
automatically just copies the files that was changed since the last run.
Of course, you have to see that your system time always is right. If you later want to
do a complete synchronization again, you just touch the backup.date file with the
date of 01.01.1970.
Also you can specify multiple sources to targets. But in this version always one source
has one target.

With which systems are the scripts designed to run?
The scripts are created for Linux, but also tested with AIX 5.x and ksh. You may
use them also with other OS but care, you could get unexpected results.
You just need the following linux compatible commands:
- find     (search files)
- cp       (copy) 
- mkdir    (creates directory)
- ksh/bash (shell)
- iconv    (convert filenames)

There are two versions of the script, one set is written for bash,
 and one is ksh (88) compatible.
-This version is ksh (kornshell) Version 88 compatible.
-This version is bash (bourne again shell) compatible.

What is to do?
First, you have to adjust some settings in the files after you extracted them. 
These are backup.sh just see down for more details!
Second, the scripts itself should not be in any target directory you plan to synchronise.

Remember, these scripts need all right to read the files/directories you plan to
backup and the right to write in the target directories.

Contents:
-mycopy.sh          # this script does the copy 
-mymkdir.sh         # this script creates new directories in the target
-isoname.sh         # converts filenames from utf-8 to ISO8859-1
-backup.sh          # main script
-mybackup.source    # Source directories, one on each line
-mybackup.target    # Target directories, one on each line
-backup.date        # file just needed to save the backup date-time.
-reset_date.sh      # you can set back the backup.date for complete backup/sync
-README.TXT         # this readme file

Of course you can change the behaviour of all files to your needs.
- isoname.sh is specific thought for saving files from linux to windows disc. 
Since newer Gnome Versions and Desktop Tools save filenames in UTF-8 can have
problems just "copy" them to the mounted windows disc or to a filesystem not supporting
UTF-8. So this isoname.sh script just translates UTF-8 to ISO8859-1 which is 
supported by most systems.

-backup.sh 
The scripts could be placed somewhere like /home/myname/scripts/backup
You have to configure your installation path in the file backup.conf
before you start the script for the first time!

What if you need to synchronize all files newer than a specific date?
Just touch the file backup.date with the date you need.
For more information see the "touch" command.
To set the date back to a very old date which syncs all files, you can use
the script reset_date.sh

Example of mybackup.source and mybackup.target
mybackup.source
/home/uli
/home/sigfried/secure
/home/backup

mybackup.target
/mnt/supersave/uli
/mnt/supersave/sigfried/secure
/mnt/supersave/backup/archive

The script so first takes /home/uli as source and saves it recursive to /mnt/supersave/uli
then it takes /home/sigfried/secure and saves it recursive to /mnt/supersave/sigfried/secure
and at least it takes /home/backup recursive saved to /mnt/supersave/backup/archive 

It makes no sense to for example have
/home saved to /mnt/supersave/home
and as second
/home/uli   to /mnt/supersave/home/uli
because the script saves recursive into directories, so the second source/target
isn't useful at all.

If you have comments, modifications or tested under other circumstances/OS I would
appreciate you mail this as info to: shell.backup@my.donster.de




---
Die hier und in den Unterverzeichnissen aufgeführten Angebote, Produkte oder Dienstleistungen werden von mir aufgrund eigener Benutzung und Erfahrung empfohlen, soweit nicht anders vermerkt.
vodafone.de



Diese Seite bewerten / Vote this site:

Rating: 1.8/5 (26 votes cast)

Disclaimer/Impressum

  visits:

(c) 2006-2009 by Stefan Hummert

Back2Main