cp file.sql.gz to file-02-17.2017.sql.zip

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

cp file.sql.gz to file-02-17.2017.sql.zip

Post by Vegan »

I use Ubuntu for want of a distribution for my database, I was wondering if anyone knows how to name a file to the date so that backups can be accumulated over time
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: cp file.sql.gz to file-02-17.2017.sql.zip

Post by requinix »

How are you doing the backups? If there's a shell command involved then you may be able to add a

Code: Select all

`date +'%m-%d-%Y'`
in it to inject the date at that location, eg.

Code: Select all

mysqldump ... > backup-`date +'%m-%d-%Y'`.sql
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: cp file.sql.gz to file-02-17.2017.sql.zip

Post by Vegan »

By mechanizing backups with a BASH script and cron, then I can go back as needed in case of a disaster

Code: Select all

sudo mysqldump -u root -p --all-databases | gzip > backup-`date +'%m-%d-%Y'`.sql.gz
I am sure anyone reading this post will see the immediate benefit to backup of the backup

Code: Select all

sudo crontab -e
add the script and voila, aged backups, then I can download with FTP and have safe backup in case something gets bricked
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
Post Reply