Script for Archiving data folderwise


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script for Archiving data folderwise
# 1  
Old 04-30-2011
Script for Archiving data folderwise

Hi,

I want to archive more than 15 days old files from /var/spool/ directory which contains 67 folders.
I have done a script for a single folder which is as follows :
Code:
 
cd /data1/ctron80/var/spool/bmaprt/
find . -mtime +15 | awk '{print "mv " $1 " /back/spool/bmaprt"}' | sh
cd /back/spool/
zip -r "bmaprt-`date '+%Y-%m-%d'`.zip" bmaprt
mv bmaprt*.zip /dump_restore/rajan_data/spool/
cd /back/spool/bmaprt/
rm*

Now I need to do same process for remaining 66 folders, involves creating same stanza 66 times.
Is there any way to short this process ?

Last edited by tuxian; 04-30-2011 at 08:09 AM..
# 2  
Old 04-30-2011
No tested.

Code:
cd /data1/ctron80/var/spool

ls -l |grep ^d |awk '{print $NF}' |while read folder
# if find command support -maxdepth  option
# find . -maxdepth 1 -type d |while read folder
do
  mkdir -p /back/spool/$folder
  find $folder -mtime +15 -exec mv {} /back/spool/$folder \; 
  cd /back/spool
  zip -r "$folder-`date '+%Y-%m-%d'`.zip" $folder
  mv $folder*.zip /dump_restore/rajan_data/spool/
  cd /back/spool/$folder/
  rm*
  cd /data1/ctron80/var/spool
done

---------- Post updated at 10:44 PM ---------- Previous update was at 10:36 PM ----------

Archive the old files into one .tar.gzip file
Code:
cd /data1/ctron80/var/spool
find . -mtime +15 -type f  > /tmp/filelist
tar --create --gzip --files-from /tmp/filelist --file /dump_restore/rajan_data/spool/repository-`date +%Y%m%d`.tar.gz
find . -mtime +15 -type f -exec rm {} \;

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

In PErl script: need to read the data one file and generate multiple files based on the data

We have the data looks like below in a log file. I want to generat files based on the string between two hash(#) symbol like below Source: #ext1#test1.tale2 drop #ext1#test11.tale21 drop #ext1#test123.tale21 drop #ext2#test1.tale21 drop #ext2#test12.tale21 drop #ext3#test11.tale21 drop... (5 Replies)
Discussion started by: Sanjeev G
5 Replies

2. Shell Programming and Scripting

Archiving files using shell script

Dear Team, I am looking for transferring files to and from the local and remote servers using SFTP commands. Currently the script is using the mget and mput commands to do the copying of the files. While I am trying to move the files from local to remote server, I would also like to archive... (21 Replies)
Discussion started by: Rads
21 Replies

3. 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

4. UNIX for Advanced & Expert Users

Convert column data to row data using shell script

Hi, I want to convert a 3-column data to 3-row data using shell script. Any suggestion in this regard is highly appreciated. Thanks. (4 Replies)
Discussion started by: sktkpl
4 Replies

5. UNIX for Advanced & Expert Users

Archiving a directory that has data ~150GB

I have a directory that need to backup, its size is about 150GB consist of multiple files and directories. I try to compress it become a single archive file using these commands: tar cjf this_archive.tar.bz2 this_archive/ or tar cf - this_archive/ | 7z a -si -t7z -m0=lzma -mx=9 -mfb=64... (3 Replies)
Discussion started by: erlanq
3 Replies

6. Shell Programming and Scripting

Shell script for log archiving

I have an nfs mount /logfile/project mounted on several of my application server machines. I have 5 jvms running on each machine and I have several machines. the jvms logs are created and rotated every day so it will look like /jvm1/logs/server.log.2010-10-27 /jvm2/logs/server.log.2010-10-27... (3 Replies)
Discussion started by: gubbu
3 Replies

7. Shell Programming and Scripting

Linear data to column data..script help seeked

Hello Take a look at following lines. This is giving me an o/p all in one array where as i want the column to be printed.How can i do it? e.g I am getting: 1575028616...... whereas i want 1 5750 28616 I am writing this small piece and trying to get this column o/p in a CSV. ... (1 Reply)
Discussion started by: ak835
1 Replies

8. Shell Programming and Scripting

creating a simple archiving script

Im trying to create a script to archive specified directories into a specified tarball backup file. This is what i want the input to look like ex. save -i '/bin/b*' -i '/bin/ls' -o backup this is what i have #!/bin/bash #save - backup file script unset myInput unset myOutput while... (3 Replies)
Discussion started by: lensmen
3 Replies

9. UNIX for Dummies Questions & Answers

creating an archiving script

Hi all. New to unix and need a little help. I am trying to create a script to archive files or directories in to a tarball. I've played a little with scripts but dont understand how to do options. What i want to be able to do is give the command any number of inputs and an output. ex.... (2 Replies)
Discussion started by: jinxe
2 Replies
Login or Register to Ask a Question