LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Backup script question ! (http://www.linuxquestions.org/questions/programming-9/backup-script-question-260685/)

emailssent 11-29-2004 06:26 PM

Backup script question !
 
Since I am new to shell scripting, i am asking this question:

I need to have aincremental backup script, that will backup the changed data(from last backup) of one system to another system(backup server)

So, I tried this
------------------------
#!/bin/sh
#
#creates backup of modified files

DATA="/home/sa/"
LIST="/tmp/backuplist_$$.txt"

set $(date)


# incremental backup:
find $DATA -depth -type f \( -ctime -1 -o -mtime -1 \) -print > $LIST
tar cfzT "/home/sa/data_diff_$6-$2-$3.tgz" "$LIST"

scp -pqr /home/sa/data_diff* 192.192.192.110:/home/backuplt/.
rm -f /home/sa/data_diff_*
rm -f "$LIST"
------------------------

But, above script is taking full backup every time whereas i need incremental backup. So, any help would be appreciated.



-jack

Hko 11-29-2004 06:41 PM

rsync!

emailssent 12-01-2004 11:21 AM

Thanks for reply,

I tried rsync, but have few doubts.

# !/bin/sh

set $(date)

rsync -e ssh -avz --password-file /root/password --delete root@192.192.192.180:/home/sa/ /home/backup/sa/ 2>&1 > /var/log/backup_log/sa_backup_$6-$4-$3-$2.log


------------
when i tried this script then it asked me for password , then i tried "--password-file" option but it is not picking password from /root/password file.


So, could some help me to find the bugs in above syntax, or tell me some method to avoid asking for password.


But i don't need to generate rsa keys with "ssh-keygen -t rsa" becz i am doing ssh with so it will create security loophole.


More info can be provided if neede.


-jack

Hko 12-01-2004 12:28 PM

Quote:

Originally posted by emailssent
when i tried this script then it asked me for password , then i tried "--password-file" option but it is not picking password from /root/password file.

[..snip..]

But i don't need to generate rsa keys with "ssh-keygen -t rsa" becz i am doing ssh with so it will create security loophole.
Why would key-authentication create a security hole, while having a clear-text password in a file would not?!?

cbe 12-01-2004 05:52 PM

I use a modified version of this script from Jason Pepas. His site seems to be down so I will just paste it all in here.

I call it via cron once a day at 1AM

Code:


00 1 * * * root /etc/backup/backup.sh

It works great, does an incremental backup everyday and a FULL backup on Sunday


first a script called backup.sh

Code:


#!/bin/sh

# jason pepas's backup script - see http://jason.pepas.com
# shell script tutorials:
http://www.freeos.com/guides/lsst/
http://www.linuxnewbie.org/nhf/intel...ashscript.html


# --------------------------------------------------
# set variables:
# --------------------------------------------------


directoryname=`date +%Y-%m-%d`"_"`hostname`"_backup"
current="current_"`hostname`
fullbackuplabel="Full Backup of "`hostname`" on "`date '+%B %e, %Y'`
fullbackupname=`date +%Y-%m-%d`"_full.tar.gz"
fullbackuplogname=`date +%Y-%m-%d`"_full.log"
incrementalbackuplabel="Incremental Backup of "`hostname`" on "`date '+%B %e, %Y'`
incrementalbackupname=`date +%Y-%m-%d`"_incremental"`date +%H%M`".tar.gz"
incrementalbackuplogname=`date +%Y-%m-%d`"_incremental"`date +%H%M`".log"


# --------------------------------------------------
# functions:
# --------------------------------------------------


fullbackup()
{
    # create backup directory
    if test ! -e /backup/$directoryname; then
        echo "Creating /backup/$directoryname directory"
        mkdir /backup/$directoryname
    fi

    # create (or update) a shortcut called current to this directory
    echo "Updating /backup/$current pointer"
    rm /backup/$current
    ln -s /backup/$directoryname /backup/$current

    # keep track of creation date of full backup (used with incremental backups)
    echo "Updating /backup/$current/lastfullbackupdate"
    date>/backup/$current/lastfullbackupdate
   
    # create backup
    echo "Running tar..."
    tar --create  --label "$fullbackuplabel" --files-from /root/scripts/whattobackup --exclude-from /root/scripts/whatnottobackup --ignore-failed-read --absolute-names --verbose --gzip --file /backup/$current/$fullbackupname > /backup/$current/$fullbackuplogname 2>&1
    gzip /backup/$current/$fullbackuplogname
    echo "Done. Created /backup/$current/$fullbackupname"
    echo "To view the log, type:"
    echo " zcat /backup/$current/$fullbackuplogname"
}


incrementalbackup()
{
    # create variable with date of last full backup
    lastfullbackupdatevar=`cat /backup/$current/lastfullbackupdate`
   
    # check for existence of incremental backup
    if test -e "/backup/$current/$incrementalbackupname"; then

        echo "Your last incremental backup was less than 60 seconds ago."
            echo "Wait a minute and try again."

    else

        # create incremental backup
            echo "Running tar..."
        tar --create --label "$incrementalbackuplabel" --files-from /root/scripts/whattobackup --exclude-from /root/scripts/whatnottobackup --ignore-failed-read --after-date "$lastfullbackupdatevar" --absolute-names --verbose --gzip --file /backup/$current/$incrementalbackupname > /backup/$current $incrementalbackuplogname 2>&1

        gzip /backup/$current/$incrementalbackuplogname
        echo "Done. Created /backup/$current/$incrementalbackupname"
        echo "To view the log, type:"
        echo " zcat /backup/$current/$incrementalbackuplogname"

    fi
}


# --------------------------------------------------
# main routine:
# --------------------------------------------------

# first get a list of all packages installed.
dpkg --get-selections > /etc/apt/selections

# clear out apt's packages
#apt-get clean

# now perform the backup.
echo "---------- Backup Script Running... ----------"

if test `date +%A` = "Sunday" && ! -e "/backup/$directoryname"; then

    # if it is sunday and you havent yet done a full backup, do so
    echo "Performing Weekly Full Backup..."
    fullbackup;

elif test ! -e /backup/$current/*full.tar.gz; then

    # if there is no current fullbackup, make one
    echo "No Current Full Backup - Performing Full Backup Now..."
    fullbackup;

else

    # otherwise, do an incremental backup
    echo "Performing Incremental Backup..."
    incrementalbackup;

fi # end if statement

echo "---------- Backup Script Done ----------"

Then a what to backup file called "whattobackup".
This is just a list "ONE ITEM" per line uses wildcards and full paths of what to backup

Code:


/boot
/etc
/home
/root
/temp
/usr/local
/var

Then a what not to backup file called "whatonotbackup".
This is just a list "ONE ITEM" per line uses wildcards and full paths of what NOT to backup.

Code:


*.mp3
*.mpg
*.avi
*.wav
*.mov
*.asf
*.rm
*.iso
*.flac
*.zip
*.exe
data.bin
/usr/local/fonts
/usr/local/games
/usr/local/j2re
/usr/local/j2re1.4.0
/usr/local/winbackup
/var/cache/apt/archives

Hope this helps,
cbe

emailssent 12-01-2004 06:35 PM

Thanks for replying Hko.

Quote:

Why would key-authentication create a security hole, while having a clear-text password in a file would not?!?
becz whenever any other person would do ssh root@liveserver from backupserver then it is not going to ask password to him. So, plz help with this issue.

thank for replying cbe, but i need to implement it through rsync, if i rsync doesn't work then i will give a try to ur backup script.
But in the mean while if u have any suggestion for my 2 line script then please give.



-jac

Hko 12-02-2004 06:02 AM

Quote:

Originally posted by emailssent
becz whenever any other person would do ssh root@liveserver from backupserver then it is not going to ask password to him. So, plz help with this issue.
No. That will only happen if that person is root at the backup server. (unless you give root's private key to the other users, which you shouldn't of course).

emailssent 12-02-2004 07:43 PM

Thanks Hko,


I was doing mistake, becz earlier i was doing ssh through root, so i thought that if
any one would do ssh then it not ask the password, but i was wrong.

Thanks for help.


-jack


All times are GMT -5. The time now is 04:40 PM.