Archiving by Time


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Archiving by Time
# 1  
Old 07-18-2008
Archiving by Time

Hi all. I am trying to set up archiving of directories, such that I keep every directory made in the past week, but just one directory per week beyond that. Using the find command, I can easily delete everything more than one week old, but can not figure out how to save one.

Each directory contains a single zip file. I'd prefer to keep the one with the largest zip file, but this is not necessary. If someone can tell me how I can keep just one directory, regardless of criteria, I would be greatly appreciative.

I realize that this could probably be done by hand, but a zip file and directory is created ~every 30 minutes, so it would be rather tedious.

Thanks for any help you can provide.

EDIT: This archiving is currently done (deleting everything more than a week old) in a shell script that is called by the program. This script creates and moves the zip file from a bunch of jpg's. Hence, I figured this was the correct sub-forum. If not, let me know and I will be glad to move it.

Last edited by aefskysa; 07-18-2008 at 06:43 AM.. Reason: Addition
# 2  
Old 07-18-2008
So is this solved or still open?

If it is still open - why not do a find to get largest of them, safe it first, and then delete all of them (if I got it right)?
# 3  
Old 07-18-2008
It is still open. I did not see an option among the man page for "find" to get the largest file. Which option is it?
# 4  
Old 07-18-2008
Sorry, might be misleading, as find can only show files compared to some size, what might give you still too many files, instead of 1 for the largest. Here is a bit lengthy explanation, how you could handle this and implement in the script you already have:

Code:
root@isau02:/data/tmp/testfeld> ll
insgesamt 36
drwxr-xr-x 2 isau users 4096 2008-07-18 13:59 .
drwxr-xr-x 7 isau users 4096 2008-07-09 14:36 ..
-rwx------ 1 root root   197 2008-07-08 10:00 array.ksh
-rw-r--r-- 1 root root    98 2008-07-17 14:31 infile
-rwx------ 1 root root   207 2008-07-04 10:10 input.ksh
-rwx------ 1 root root   328 2008-07-08 09:21 loop.ksh
-rwx------ 1 root root    27 2008-07-18 13:59 mach.ksh
-rw-r--r-- 1 root root   845 2008-07-08 07:58 NMEA.txt
-rw-r--r-- 1 root root     0 2008-07-18 13:55 temp2.txt
-rwx------ 1 root root   174 2008-06-27 13:25 weekend_is_close.ksh
root@isau02:/data/tmp/testfeld> find . -type f -exec ls -la {} \;| awk '{print $5,$NF}'
207 ./input.ksh
328 ./loop.ksh
845 ./NMEA.txt
98 ./infile
197 ./array.ksh
27 ./mach.ksh
0 ./temp2.txt
174 ./weekend_is_close.ksh
root@isau02:/data/tmp/testfeld> find . -type f -exec ls -la {} \;| awk '{print $5,$NF}'| sort -k 1,1n
0 ./temp2.txt
27 ./mach.ksh
98 ./infile
174 ./weekend_is_close.ksh
197 ./array.ksh
207 ./input.ksh
328 ./loop.ksh
845 ./NMEA.txt
root@isau02:/data/tmp/testfeld> find . -type f -exec ls -la {} \;| awk '{print $5,$NF}'| sort -k 1,1n| tail -1| awk '{print $2}'
./NMEA.txt


Last edited by zaxxon; 01-20-2009 at 05:45 AM.. Reason: removed a domain name
# 5  
Old 07-18-2008
That is quite helpful, but seems to be missing the final step. Once I pick out that file, how can I execute any other command on it? I am thinking I just want to 'touch' that file and make the date far enough in the past that the script will cease caring about it. Thanks again.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Archiving or removing few data from log file in real time

Hi, I have a log file that gets updated every second. Currently the size has grown to 20+ GB. I need to have a command/script, that will try to get the actual size of the file and will remove 50% of the data that are in the log file. I don't mind removing the data as the size has grown to huge... (8 Replies)
Discussion started by: Souvik Patra
8 Replies

2. Shell Programming and Scripting

Help to reduce time of archiving

hi all, i have written the following script that does this work: 1. copy large logs files from one server to another. 2. then unzip this files and extraxt from these large https logs only those fields that are neccesary. 3. then archive the extracted logs to new files. BUT the problem is... (7 Replies)
Discussion started by: arrals_vl
7 Replies

3. Shell Programming and Scripting

Simple archiving

Hi, I am a UNIX novice and was trying to write a bash script that would read two parameters, $1 would be the archive file path where the archiving path is passed, so the archiving script will write to this file path. The second parameter will be the directory path to the library which will... (0 Replies)
Discussion started by: pernuntium
0 Replies

4. UNIX for Advanced & Expert Users

Help with archiving using find

Dear Unix Experts, I am trying to backup some legacy data based on date. I am pasting a small portion from the ls -al command from my session for reference. athena>ls -al ./nmr/exam1d_13C: total 32 drwxrwxrwx 3 root root 4096 May 1 2008 1/ drwxrwxrwx 3 root ... (1 Reply)
Discussion started by: jaison75
1 Replies

5. UNIX for Dummies Questions & Answers

Archiving and move files in the same time

Hi All, I have tried so many command but none work like i wanted. I would like archive which i assume it will move the files and archive it somewhere. for example: if i have a folder and files: /home/blah/test /home/blah/hello /home/blah/foo/bar i would like to archive folder... (6 Replies)
Discussion started by: c00kie88
6 Replies

6. UNIX for Dummies Questions & Answers

Archiving Problem

Hi friends I work on UNIX Operating system and I have many servers. ADM server make archiving for special data every day inside XYZ directory at specific time,the next time SPERADM server will take that archiving data to put them in same directory (inside SPERADM server). Now archiving... (2 Replies)
Discussion started by: bintaleb
2 Replies

7. Shell Programming and Scripting

Archiving

Hi, I want to archive below directory ex: /home/oracle/dd0 sub-directories in dd0 /home/oracle/dd0/backup/backup1 /home/oracle/dd0/backup/backup2 /home/oracle/dd0/dmp ....etc I want a command(tar) which will let me archive the above directory excluding *.dmp(dump files), *.log(log... (1 Reply)
Discussion started by: dreams5617
1 Replies

8. Shell Programming and Scripting

Archiving Users

Hello Gurus, I have a requirement where I have to remove users that have not logged into our unix box last 90 days. I want to script this one and remove the users automatically now and then. Has any one ever done this before, if so please give me some sample code. I am not a good unix... (2 Replies)
Discussion started by: suseesk
2 Replies

9. UNIX for Dummies Questions & Answers

Archiving

I am looking for some advice. I have some files on a Unix server, which contain symbolic links. I need to copy these over to a nfts environment, but wish to keep the symbolic links intact. Any ideas? (7 Replies)
Discussion started by: rmasonuk
7 Replies
Login or Register to Ask a Question