LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-29-2004, 06:26 PM   #1
emailssent
Member
 
Registered: Sep 2004
Posts: 312

Rep: Reputation: 30
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
 
Old 11-29-2004, 06:41 PM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
rsync!
 
Old 12-01-2004, 11:21 AM   #3
emailssent
Member
 
Registered: Sep 2004
Posts: 312

Original Poster
Rep: Reputation: 30
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
 
Old 12-01-2004, 12:28 PM   #4
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
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?!?
 
Old 12-01-2004, 05:52 PM   #5
cbe
LQ Newbie
 
Registered: Jul 2001
Posts: 19

Rep: Reputation: 0
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
 
Old 12-01-2004, 06:35 PM   #6
emailssent
Member
 
Registered: Sep 2004
Posts: 312

Original Poster
Rep: Reputation: 30
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
 
Old 12-02-2004, 06:02 AM   #7
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
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).
 
Old 12-02-2004, 07:43 PM   #8
emailssent
Member
 
Registered: Sep 2004
Posts: 312

Original Poster
Rep: Reputation: 30
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Using CP in my backup script. Echo Kilo Programming 6 06-01-2005 08:43 AM
backup script question lordofring Linux - Software 7 04-18-2005 10:25 AM
Script Backup Buto Linux - General 2 10-18-2004 05:56 PM
Backup Script imsajjadali Linux - General 7 01-28-2004 03:30 PM
backup script lhoff Programming 2 05-28-2003 11:37 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:14 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration