Script required to copy and delete files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script required to copy and delete files
# 1  
Old 12-30-2008
Script required to copy and delete files

Hi All,

I have written a script to ensure all my ARCHIVE files are backed up retaining the directory structure.
The Script is--

#!/bin/sh
# Script to take backup of DCS Folders
# The file locations are /ftp/edi_ftp/edi_p/dcsftp/DCS/*/ARCHIVE
DCSITIME=$(perl -e '($ss, $mm, $hh, $DD, $MM, $YY) = localtime(time());printf "%04d%02d%02d%02d%02d", $YY + 1900, $MM + 1, $DD, $hh, $mm')
mkdir /backup/proact/dcs_backup_files/OTHERS/$DCSITIME

for i in `ls -d /ftp/edi_ftp/edi_p/dcsftp/DCS/*/ARCHIVE|cut -f1,2,3,4,5,6,7 -d /`; do cp -pr $i /backup/proact/dcs_backup_files/OTHERS/$DCSITIME/; done

But my requirement is.... I need to take the backup of these files and delete only copied files from original location (Inside ARCHIVE directory there wont be any Sub directories, it will have only files). I cannot delete using normal delete because these files are very dynamic and if I use only `rm ARCHIVE/*`, I have the risk of deleting files which got created between the time of my backup and deletion. I cannot simply move the directory and recreate it because; application may fail at that point of time.

I need help to take the backup with folder structure intact (I'm able to do in the above script) and delete only copied files inside ARCHIVE Folder.



How can I do this??


Regards,

Nagu
# 2  
Old 12-30-2008
Maybe if you use the tee command to pipe the output from your ls command to a file and then use that file as input to a for command that deletes all the files that were copied.
For instance, I use ls -d /ARCHIVE/*|cut -f1,2,3,4,5,6,7 -d /| tee /tmp/filelist. Then use a for command like for i in `cat /tmp/filelist`; do rm $i; done;
# 3  
Old 12-30-2008
But in this case I will be deleting the directory ARCHIVE itself.

I need to delete only copied files
# 4  
Old 12-30-2008
srnagu,

while copying if you add tag like 'COPY' and while greping, only grep files which you copied and delete them.

- nilesh
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Copy files based on specific word in a file name & its extension and putting it in required location

Hello All, Since i'm relatively new in shell script need your guidance. I'm copying files manually based on a specific word in a file name and its extension and then moving it into some destination folder. so if filename contains hyr word and it has .md and .db extension; it will move to TUM/HYR... (13 Replies)
Discussion started by: prajaktaraut
13 Replies

2. Shell Programming and Scripting

Script needed to delete to the list of files in a directory based on last created & delete them

Hi My directory structure is as below. dir1, dir2, dir3 I have the list of files to be deleted in the below path as below. /staging/retain_for_2years/Cleanup/log $ ls -lrt total 0 drwxr-xr-x 2 nobody nobody 256 Mar 01 16:15 01-MAR-2015_SPDBS2 drwxr-xr-x 2 root ... (2 Replies)
Discussion started by: prasadn
2 Replies

3. Shell Programming and Scripting

Help with script to copy/rename files, then delete by date

Hi All, I am new to scripting and am looking for some assistance setting up a script. Basically I need the script to scan a folder for the newest files and make a copy of those files, adding a month to the date stamp. I also need this script to delete the previously copied files to save space.... (4 Replies)
Discussion started by: Lucid13
4 Replies

4. Shell Programming and Scripting

Any command to delete files from source dir after SFTP copy

Hi, I am currently using SFTP 'put' command to copy all files to remote server and then delete the copied files from source directory. Can anyone help me with a single command to copy and remove files in one go? Thanks and Regards, Chetan Vyas (5 Replies)
Discussion started by: chetancrsp18
5 Replies

5. Shell Programming and Scripting

awk script required to compare two files

HI friends, I have two files. File2 2nd column need to be compared with file1 3rd column.If ID match found, then save in different file as file1 data followed by file2. file1: No;age;id;name 1;24;37h;name1 2;22;67e;name2 4;48;9r;name3 6;67;9i8;name4 file2: exp;id;pos... (9 Replies)
Discussion started by: vasanth.vadalur
9 Replies

6. Shell Programming and Scripting

Loop folders, delete files, copy new ones

Folks, I am hopeful that you may be able to help me out with writing a script that can be run nightly (as cron?) to loop through all subfolders within the "/media" directory, delete all of the files in each of them, and then copy in all of the files from the "/home//sansa" directory to each of... (6 Replies)
Discussion started by: acraig
6 Replies

7. Shell Programming and Scripting

Using RCP to copy and delete the files from Windows Drive

Hi, I have a requirement to copy the files from C drive on Windows to UNIX, once the files are copied I need to delete them from that drive (C:). A drive is also on same network as my unix, so I was asked to use RCP for copying the files. Can any one have the syntax to copy the files from... (0 Replies)
Discussion started by: Raamc
0 Replies

8. Shell Programming and Scripting

Shell script for searching a record,copy to a file and then delete it

Hi, I have a requirement in hand: I have a file with millions of records say file 1.I have another file, say file 2 which has 2000 records in it. The requirement is to read file2 , and remove the read record from file 1 and move i to a seperate file, file 3. For eg: Read file 2, get the... (5 Replies)
Discussion started by: kumara2010
5 Replies

9. Shell Programming and Scripting

Shell script required to uncompress and untar files

I need a shell script to Uncompress untar all the files present in the directory (it should Uncompress an untar files present in its sub folders also) In my work I get lots of tar files to untar and update the server, for this each time in need to type Step1) “ Uncompress xyz1-3.tar.z”... (2 Replies)
Discussion started by: arewe
2 Replies
Login or Register to Ask a Question