Create a backup utility


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Create a backup utility
# 1  
Old 12-07-2009
Create a backup utility

hi there,

looking for a tad assistance if at all possible, im trying to create a backup that will backup all files with a particular .ext to a new folder with the same file name but also with the last modified time and date in the file name ie
so if the file information.txt was last modified at 03:15:34 27 Apr 2009 the backup file would show information_(03:15:34 27/04/2009).txt

any sugestions on how i can achieve this? so far all ive managed is

Code:
cp *txt ../backup/word/

sorry im really terrible with this shell scripting Smilie
# 2  
Old 12-08-2009
You can't use slashes in filenames since they are separators for directory structures. Example

Code:
$> ll *txt
-rw-r--r-- 1 root root 0 2009-12-08 07:50 bla1.txt
-rw-r--r-- 1 root root 0 2009-12-08 07:50 bla2.txt
$> for file in *.txt; do cp -p $file subdir/`echo $file| sed 's/\.txt//g'`_`ls -l $file| awk 'NF > 2 {print $6"_"$7}'`.txt; done
$> ll subdir
total 8
drwxr-xr-x 2 root root  4096 2009-12-08 07:53 .
drwxr-xr-x 4 isau users 4096 2009-12-08 07:50 ..
-rw-r--r-- 1 root root     0 2009-12-08 07:50 bla1_2009-12-08_07:50.txt
-rw-r--r-- 1 root root     0 2009-12-08 07:50 bla2_2009-12-08_07:50.txt

If you have filenames with blanks in them you might want to use a while loop instead of the for loop.
# 3  
Old 12-08-2009
Depending on the possibilities of your 'date' command.
Type 'man date' and search for an -r option to retrieve the date from the datestamp of the file, else you'll have to use 'stat' and parse the data returned.

I recomend to use a date format that puts the most significant at the beginning for a better sorting. It could also be better to avoid spaces and ':' in the date string.
Something like
information_09-12-08_07-49-00.txt would be returned with
Code:
FILE=information.txt
NEWFILE="${FILE%*.}_$(date -r ${FILE} +%y-%m-%d_%H-%M-%S).${FILE##*.}
echo "New file name: $NEWFILE"

You can modify the date format at your convenience. (see 'man date')
# 4  
Old 12-08-2009
hello
what you are trying to do is devastating. I must say .
#cp *.txt /some_dir/
what this does is the shell expands any metacharacter to its real value . for e.g. if you have files like abc.txt def.txt ddd.txt then the above shell command expands to.
#cp abc.txt def.txt ddd.txt /some_dir
this apparently doenst make any sense.
So you better use find for this purpose.
aka find/exec to do this work
find . iname "*.txt" -mtime blah_blah(look at the date format) -exec cp {} /some/path/to/backup/ \;
regards.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Solaris

How to backup (create image) SunOS 5.10 sparc?

Hello guys! I'm a newbee in Solaris systems. There is an issue, that I've got: I have to make an iso image of my solaris system. How can I do it? with dd utility? Clonezilla does not support spark, so it cant do backup. pls help! Is this solution: Creating a Solaris Flash Archive... (21 Replies)
Discussion started by: 2fat2fly
21 Replies

2. SCO

Help about create backup of SCO openserver 5.0.7

hi guys im beginner in unix and have many problem with this. i have one old machine that Sco unix OpenServer 5.0.7 installed on it. i wana backup from all partition of hard disk and restore it on another unix machine. how can i do that ? thing like hard to hard for windows !!! i only know how... (14 Replies)
Discussion started by: farzad226
14 Replies

3. Shell Programming and Scripting

Create database using Backup file

Hi, I have backup file of database in my server. I want to create a that database in the same Mysql Server. How can I do that? Please send the steps to create the database using backup file? Thanks a lot, (1 Reply)
Discussion started by: aish11
1 Replies

4. Shell Programming and Scripting

How to create a simple shell script to backup

Hello - I am in process of deleting many files which are older than 4 weeks. For example I am inside: /subsystem/prod/ Files are with various extentions, but anything older than 4 weeks should be deleted. What would be the most simplest script to acheive this? (4 Replies)
Discussion started by: DallasT
4 Replies

5. Filesystems, Disks and Memory

How to create mondo backup for size > 4.5 GB

Hello Friends, I use mondoarchive to take a bootable backup of my system on a DVD. But whenever there are large files on the system, i.e. the size of the entire backup increases beyond 4.5 GB, the mondoarchive utility does not take any backup. This is quite obvious because the size of DVD is... (1 Reply)
Discussion started by: shamik
1 Replies

6. Shell Programming and Scripting

Find directory and create backup

What I'm attempting to do is create a script that will do a search for directories that meet the following criteria: find . -name "config" -type d this comes back with: ./dir1/anotherDir/test_dir/config ./dir1/anotherDir/test_dira/config ./dir2/test/test_dir/config The results could... (4 Replies)
Discussion started by: cbo0485
4 Replies

7. UNIX for Dummies Questions & Answers

Best unix incremental backup utility?

Hello everyone. Could you please advise of what would be the best Unix (Debian 4) program for regular (daily or weekly) incremental backups? I'm not sure whether the backups will be stored on a "backup" drive on the same system or on an external "backup" system, but we would like to have a... (2 Replies)
Discussion started by: nottrobin
2 Replies

8. Windows & DOS: Issues & Discussions

Windows XP backup utility

I am trying to use the Windows XP's backup utility (start -> all programs -> Accessories -> System Tools -> Backup) to backup the whole system to another drive or a large USB flash drive to safeguard myself and the files. However, the backup utility gives error in both cases, ie. it won't backup to... (4 Replies)
Discussion started by: milhan
4 Replies

9. Programming

Using make utility to create an mini-app

The following is my makefile. When I run "make", it gives me a bunch of error. I've compiled each file separately and there are no compilation errors. The target is "monprc". Have a look below: monprc: monprc.o monrep.o dsz.o cc -o monprc monprc.o monrep.o dsz.o monprc.o: monprc.c... (1 Reply)
Discussion started by: Yifan_Guo
1 Replies
Login or Register to Ask a Question