Linuxathome.net
https://www.linuxathome.net/forum/

Help - How to delete old backup files script?
https://www.linuxathome.net/forum/viewtopic.php?f=3&t=111
Page 1 of 1

Author:  direwolf [ Sat Oct 05, 2002 3:46 pm ]
Post subject:  Help - How to delete old backup files script?

I use the below script to backup some info on my Red Hat 7.2 box and place it to a mounted dir on my Win2k box.

The files are named with the creation date at the start like this:

2002_1005_030000_docs.tar.gz

What I want to be able to do is get the script to check the folder with the backups in it and delete any previous copies that are older than x days.

How do I do this?

Quote:
#!/bin/bash
# archives important files
clear
DATE=`date +%Y_%m%d_%H%M%S`

BACKUP_DOCS_NAME=$DATE"_docs.tar.gz"
echo Operation begun at $DATE
DOCS_DIR="/home/server/documents/"

ARCHIVE_DEST_DIR=/home/qoc-s/backup/

echo Files will be stored in $ARCHIVE_DEST_DIR
echo ===============================
echo

echo "tarring and gziping the files to $ARCHIVE_DEST_DIR$BACKUP from $DOCS_DIR"
tar -czf $ARCHIVE_DEST_DIR$BACKUP_DOCS_NAME $DOCS_DIR

Author:  redlander [ Mon Oct 07, 2002 2:23 am ]
Post subject: 

easiest way is to let find do all the work:

find /home/qoc-s/backup/ -name '20*' -mtime 7 -exec rm -rf {} \;

I think that's the right syntax...it should kill any file older than 7 days.

edit: for some reason it won't let me put a plus sign in my post. there should be a plus sign before the 7.

Page 1 of 1 All times are UTC + 10 hours [ DST ]
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/