Script to delete oldest backup folder

Status
Not open for further replies.

eirik.lars1

Explorer
Joined
Jul 16, 2016
Messages
55
I back up my lightroom catalog to my free nas server on a regular basis. The folders get named "YYYY-MM-DD XXXX". Inside the folders are the lightroom catalog files. I want to keep maybe the newest five backup folders, and have a shell script that regularly deletes the oldest folders. Can anyone help me with the commands?

I looked at this thread post # 38: Script to delete old backup file?(Acronis, OO DiskImage, etc). Is there a way to modify that command to suit my needs?
 

snaptec

Guru
Joined
Nov 30, 2015
Messages
502
Something like:

find /mnt/path -mtime +10 | xargs rm -rf

Should be suitable.
It will delete everything older than 10 days.




Gesendet von iPhone mit Tapatalk
 
Last edited by a moderator:

eirik.lars1

Explorer
Joined
Jul 16, 2016
Messages
55
Yes, but I would always like keep x amount of backup folders. Even if its older than 10 days.
 

snaptec

Guru
Joined
Nov 30, 2015
Messages
502
Sorry, misunderstand that
Try:

ls -r /path/ | tail -n +5 | rm

Will list the directory.
Tail the first 5 lines.
Executes rm on the rest.

Maybe put it in a sort, just test and have a look what the output is before you pipe it to rm

Just out of my head, but should work.


Gesendet von iPhone mit Tapatalk
 
Last edited by a moderator:

Arwen

MVP
Joined
May 17, 2014
Messages
3,611
@eirik.lars1
You might take a look at your backups from the perspective of ZFS snapshots. I re-did my backup
scheme, first for my clients then later for my FreeNAS.

Using Rsync as the client backup tool, I can reduce the time to perform backups. But, since I have
space on the FreeNAS, I wanted to keep more than one. So instead of a full backup, I use non-expiring
ZFS snapshots on the client backups. Whence I start running low on space, I'll delete the oldest.

For the FreeNAS backups I had orginally kept multiple full copies of my FreeNAS. But, this did not
make sense with ZFS. So I started using snapshots on the backup disk. Saves space and I get multiple
FreeNAS server backups.

So if your lightroom catalog is not completely changed between backups, then you might be able to
save some space by snapshotting after each backup. Then the delete of oldest would be a ZFS dataset
destroy, (which would potentially be faster than rm).
 
Status
Not open for further replies.
Top