I need to create a cron job that will tar all images created within the last X days.
I use cron jobs on my websites by setting them up in CPanel, but I’m not an experienced script writer when it comes to unix stuff. Any help will be appreciated.
This is my cron job:
0 4 * * 1 tar pzvcf /home/xxxxxx/public_html/backups/images_backup.tar /home/xxxxxx/public_html/images/products
Use find to locate all the images and feed them to tar.
Something like this should give you file created in the last 2 days (the -2 means < 2*24 hrs)
Something like this probably does the whole job:
tar cf <file>creates a tarball,tar af <file>appends to an existing tarballThe
-T -tells tar to read the list of commands from stdin.The find command echos the list of matching files to stdout.
The
|joins the stdout of the find to the stdin of the tar: so tar should add all the file found by the find.