We were taking mysql backups using a very simple shell script which was using mysqldump as below.
#echo "Starting the script";
# create directory if it doesn't exist
if [ ! -d "$OLDBACKUP" ]; then
# create direcotry
# set file names by appending date to each file
# take db backups
mysqldump -u $USER -p$PASSWD -n -c myDbName >Â $dbName;
# move the file to sql_files directory
mv $dbName $OLDBACKUP
We were keeping old backup files but we knew that we would need to remove the backup files older than two weeks or a month. I was thinking what to do and after some studying I found the following one line, would help us remove files older than x number of days.
find /home/my_backup/sql_files -type f -mtime +15 | xargs rm
Where 15 could be changed to any number of days and it will remove all the files older than that number of days recursively, using this command. This command won’t delete any special files or sub directories.