I need help with a backup code


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting I need help with a backup code
# 1  
Old 11-03-2005
Network I need help with a backup code

I'm having an issue with a problem
A problem with this backup script is that if you backup the same file twice, you may get a warning message because you're overwriting an existing file. You could suppress the warning message, but a better solution is to save a series of backups distinguished by numbers. The first time you type backup foo.c, it copies it to foo.c.1. Then you make some changes to foo.c and type backup foo.c again; the script notices that foo.c.1 is already there, so it copies foo.c to foo.c.2 instead. The third time, you get foo.c.3, and so on

Here is the code I have so far:

#!/bin/csh -f

file ($*)
set num=1

while (-e $file.$num)
@ num = $num +1

do
cp ${file} ${file}.$num

if anyone could fill in the gaps or tell me where I'm going wrong here.. it would be greatly appreciated
# 2  
Old 11-05-2005
Here is a ksh script. This script will need a file name to backup. It will backup only if the file has changed (content wise) compared to the last backed-up version.


Code:
[/tmp]$ cat backup.ksh 
#! /bin/ksh

[ -z "$1" ] && echo "No file to backup" && exit 1 || FILE="$1"

VER=$(ls -l $FILE.* 2>/dev/null | wc -l)
VER=$(($VER))

cmp -s "$FILE" "$FILE.$VER"

if [ $? -gt 0 ] ; then
        VER=$(($VER + 1))
        cp "$FILE" "$FILE.$VER"
        echo "Backed up $FILE to $FILE.$VER"
else
        echo "No backup taken."
fi ;

Code:
[/tmp]$ ls -l foo.c*
-rw-r--r--    1 -------- g900           19 Nov  5 02:52 foo.c
[/tmp]$ ./backup.ksh 
No file to backup
[/tmp]$ ./backup.ksh foo.c
Backed up foo.c to foo.c.1
[/tmp]$ ./backup.ksh foo.c
No backup taken.
[/tmp]$ ls -l foo.c*
-rw-r--r--    1 -------- g900           19 Nov  5 02:52 foo.c
-rw-r--r--    1 -------- g900           19 Nov  5 02:57 foo.c.1

vino
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with Backup Shell Script for Network Device Configuration backup

HI all, im new to shell scripting. need your guidence for my script. i wrote one script and is attached here Im explaining the requirement of script. AIM: Shell script to run automatically as per scheduled and backup few network devices configurations. Script will contain a set of commands... (4 Replies)
Discussion started by: saichand1985
4 Replies

2. Shell Programming and Scripting

rsync backup mode(--backup) Are there any options to remove backup folders on successful deployment?

Hi Everyone, we are running rsync with --backup mode, Are there any rsync options to remove backup folders on successful deployment? Thanks in adv. (0 Replies)
Discussion started by: MVEERA
0 Replies

3. Shell Programming and Scripting

Backup code with two inputs

Hi how can i backup files setrain size Thanks (1 Reply)
Discussion started by: lio123
1 Replies

4. UNIX for Advanced & Expert Users

backup a file and keep every version of the backup

I am trying to backup my .bash_history and I want to keep every version of the backup. I am thinking to put one of these in my crontab. 0 0 * * 0,3 cat .bash_history > boo 0 0 * * 0,3 cp .bash_history boo I would like the backups to be called boo1, boo2, boo3, etc. I would like to keep... (7 Replies)
Discussion started by: cokedude
7 Replies

5. UNIX for Dummies Questions & Answers

backup

Hi guys need your help!.... i'll have to do a backup of the entire files systems of the one server , but i have to do to another server because we do not have a tape device or some, do you know what instruction i have to use? the backup server is a linux box and the server to being backup is a... (7 Replies)
Discussion started by: clab
7 Replies

6. Filesystems, Disks and Memory

Exit code 137 on a backup

Can some one tell me what it means to get a exit code od 137 from a cron scheduled backup on HP-UX. Also if you know of a book that has the HP-UX codes that would be great. Thanks (4 Replies)
Discussion started by: twins
4 Replies

7. SCO

Backup to SCSI Tape Backup aborts

I am trying to make a full backup of my system using the cpio command. The Tape Unit is a SCSI DDS. The process started fine but after about 30 minutes, it just stopped and showed the following message: 1755 Signal 31 - Core dumped Any idea of what is causing this and how to fix it? ... (4 Replies)
Discussion started by: zionpc
4 Replies

8. UNIX for Dummies Questions & Answers

Check backup file size on backup tape

Hi, I performed backup on tape and I want to append more files to my previous backup on the same backup tape. But before I do that I need to know the backup file size of the first backup I performed so that I know the available size on the backup tape. Can someone help me what command I will use... (0 Replies)
Discussion started by: ayhanne
0 Replies

9. UNIX for Dummies Questions & Answers

The best backup

I am taking a class all about linux. Where where asked to find the best backup program. We never did agree and are system was set up with scp because some one already knew how to use it and thus the quickest to set up. Great example of legacy support. However, on my computer i do not have a... (1 Reply)
Discussion started by: macdonto
1 Replies
Login or Register to Ask a Question