Trim my config backups

ethereal

Guru
Joined
Sep 10, 2012
Messages
762
i have a script that copies my config file - once a day. i have hundreds can somebody help me with a way of automatically trimming them to say 50 ?

my script is :
cp /data/freenas-v1.db /mnt/Storage/Storage/ConfigBackups/`date +%Y%m%d`_`cut -d' ' -f1 /etc/version|cut -d'-' -f2`.db

my script runs from a cron job. which is the easiest way to trim using my unc path?
the location is \\FreeNAS\Storage\ConfigBackups

thank you
 
Joined
Jan 4, 2014
Messages
1,644
Code:
find /mnt/Storage/Storage/ConfigBackups/* -atime +31 -delete


This will keep a month's worth of backups. Suggest you take a copy of your backups and test this out first before putting it into production.
 
Last edited:

ethereal

Guru
Joined
Sep 10, 2012
Messages
762
Code:
find /mnt/Storage/Storage/ConfigBackups/* -atime +31 -delete


This will keep a month's worth of backups. Suggest you take a copy of your backups and test this out first before putting it into production.
thanks for your reply. where do i run the command
 

ethereal

Guru
Joined
Sep 10, 2012
Messages
762
i created a cron job with:
find /mnt/Storage/Storage/ConfigBackups/* -atime +31 -delete

and it worked great
 
Joined
Jun 2, 2019
Messages
591
Here is an example script I run as a weekly cron, which replicates using the GUI with export secret seed option.

Code:
#!/bin/sh

FILENAME="`hostname -s`-`cut -d' ' -f1 /etc/version`-`date +%Y%m%d`.tar"

#echo $FILENAME

tar -cvlf /mnt/data/Software/truenas/$FILENAME --strip-components=2 /data/freenas-v1.db /data/pwenc_secret

echo "Backup $FILENAME created"

find /mnt/data/Software/truenas/NAS-?-TrueNAS-*.tar -mtime +365 -exec rm {} \;




Make sure it has execute permissions

Code:
chmod a+x {filename}


Add to cron tasks

Code:
/bin/sh /mnt/data/Software/truenas/backup.sh
 
Top