// Redhat
I have this code working, but need to add one more qualification so that I don't overwrite the files.
#!/bin/sh
cd /P2/log/cerner_prod/millennium/archive/
for f in *
do [ -f "$f" ] || continue #If this isn't a regular file, skip it.
[ -e "/P2/backup/$f" ] && continue #If a backup already exists, skip it.
cp "$f" /P2/backup/ # Make a backup copy.
done
What I like to do is:
1) compare the size of the same file (i.e. p2_000001.gz).
2) if the file size (p2_000001.gz) under /P2/backup/ is larger than that under /P2/log/cerner_prod/millennium/archive/, then skip it
3) if if the file size (p2_000001.gz) under /P2/backup/ is smaller than that under /P2/log/cerner_prod/millennium/archive/, then copy or overwrite
In this case, /P2/backup/ will have always the latest file.
Please advise. Appreciate your help!