Last month file archiving script

It was once necessary to write a script that was supposed to archive only files with the date of the last month from one folder, put the archive in a separate directory and delete the files that were archived.

Here is the script itself:

zip -rm -tt $(date +%Y-%m-01) -t $(date +%Y-%m-01 -d 'last month') "/srv/samba/archive/$(date +%Y-%m-%d)" /srv/samba/dir/

An example of adding to /etc/crontab to automatically start every first day of the month at 9.30:

30 9 1 * * root /backups/scripts/ktb/zip_checks.sh > /dev/null 2>&1

See also my other scripting articles.

Leave a comment

Leave a Reply