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

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;

But in this case I will be deleting the directory ARCHIVE itself.

I need to delete only copied files

srnagu,

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

  • nilesh