Hi,
This is what I am actually doing:
Code:
tar -vzcf "/var/app-archive/app-docs-`date +%Y%m%d`.tar.gz" --remove-files `find /var/app-docs/ -type f -mtime +90 -print`
The files returned by the find command are of 1 GB in total and the free disk space is 0.75 GB hence I included the --remove-files options. I have not used that option for testing purpose on the live server.
colucix:- You have invalidated my belief that tar would add a file and delete it side by side and then add another and delete it and so will it go on with the rest of the files returned by the find command so as not to run out of the disk space. I was wrong.
Yup, the man page of tar clearly says:
Quote:
--remove-files
remove files after adding them to the archive
|
To avoid the problem of running out of disk space: I had written this script earlier:
Code:
for DIRECTORY in app-docs app-other-docs; do
find /var/${DIRECTORY}/ -type f -mtime +90 > /var/tmp/files-older-than-90-days.list
if [ -s /var/tmp/files-older-than-90-days.list ]; then # Proceed only if the list is Not Empty
#
while read FILE; do
mkdir -vp "/var/tmp/${DIRECTORY}-Backup`dirname "$FILE"`" # Cutting the File Name Off. Creating Directory Hierarcy.
mv -v "$FILE" "/var/tmp/${DIRECTORY}-Backup`dirname "$FILE"`/" # Moving the File.
done </var/tmp/files-older-than-90-days.list
#
rm -f /var/tmp/files-older-than-90-days.list
#
cd /var/tmp/${DIRECTORY}-Backup/
tar -czvf /var/app-archive/${DIRECTORY}-`date +%Y%m%d`.tar.gz *
rm -rf /var/tmp/${DIRECTORY}-Backup # Removing the Direcotry.
fi
done
It went fine and moved hundreds of files in the temporary location so the disk space remained the same and then tar
red the temporary directory and removed it.
However, because of special symbols including white spaces and (), -, - and other symbols not known in advance the script broke after moving and tar
ring hundreds of files and then overwrote the tar file with only a couple of empty directories. All data were lost!
I quoted the FILE variable above so that mkdir would not fail if there were spaces or special symbols in the directory names. Still somehow the script broke and loop got re-executed for the same first directory: app-docs resulting in moving the original files and packing only directory names by re-writing the tar file and then deleting the original files.
I am loaded with escalations!
What should I do?
I saved the contents of the "find" command because the complete structure or hierarchy of every file is to be maintained.
for example:
/var/app/dir1/dir1a/file1
/var/app/dir2/dir2a/file1
moving the second file will overwrite the first file in the destination folder: archive
if the parent directories were not created.
I changed the logic and use the find command along with the tar command as posted earlier.
I think I have explained my problem here.