Datetime Stamp for File name in Bash
31 Mar 2010
I don't like this entry's title but I was searching for this and it took me a while to find something this simple.
#!/usr/bin/env bash NOW=`date '+%Y%m%d%H%M%S'` cp production.sqlite3 production-backup-$NOW.sqlite3 echo "production database backed up to db/production-backup-$NOW.sqlite3"
This simple script will copy the "production.sqlite3" and create a copy named production-backup-20100331074423.sqlite3 or YYYYmmDDHHMMSS. You can format the date anyway you like. Read here for more info.