I currently backup a MySQL docker container using a shell script, it dumps the mysql file into a relative directory, such as..
set-e
TODAY=`date +"%d%b%Y"`
mysqldump -uroot -p"$MYSQL_ROOT_PASSWORD" -h $MYSQL_HOST --all-databases | gzip > /data/mysqldb/$TODAY/all-databases-$TODAY.sql.gzI need to create a restore script that will read the $TODAY and determine which is most recent. How do I do this? :S
11 Answer
This is the approach i used. I have a working backup script with it.
CD into the backup DIR.
cd backup_dir && ls -t | head -n 2-t -> sort by modification time, newest first
In a script:
LAST_2_BACKUPS=$(ls -t | head -n 2) 3