A (cron) job to run if file has changed
I need to backup a live sqlite db by running a command once a day. Only if the db file has changed since last backup. How could it be achieved on Centos 8 ?
The touch
command has the ability to set a file's times to be the same as another file.
The BASH shell can test
to see if one file is newer than another [ a -nt b ]
.
What you can do then is
- Set a reference file's times to be the same as your db file times using touch.
Then have a script run once per day that checks if the db file is newer than the reference file.
- If it is newer then update the reference file's times to be the same as the db file and backup the db file.
- Otherwise do nothing.