16

I am currently taking database backup manually using phpmyadmin export as a sql dump,the resulted file name will be spbkYYMMDD(Y;year m:month D:day).Is there any way to automate db backup so that i get sql dump for regular intervals and the file name should automatically generated correspondingly .can you explain me the logic.

5
  • do u need it as a web interface to do ?
    – Sudantha
    Jul 11, 2011 at 4:49
  • What do you mean by needing a web interface? What will you be having in the interface?
    – Balanivash
    Jul 11, 2011 at 5:09
  • we can give the time backup interval text box to capture the time interval
    – n92
    Jul 11, 2011 at 5:15
  • @Vinay: check the answer. Have Updated it
    – Balanivash
    Jul 11, 2011 at 5:36
  • 1
    You can simply use mysqlbackupftp.com. Connect MySQLBackupFTP tool to your phpMyAdmin and create a schedule to backup your databases. Jan 10, 2017 at 9:02

5 Answers 5

8

Run crontab in unix shell and create the rule to launch process for creating database backup

 0 0 * * * /usr/local/bin/mysqldump -uLOGIN -PPORT -hHOST -pPASS DBNAME | gzip -c > `date “+\%Y-\%m-\%d”`.gz

Also check this

EDIT

The web interface you only have to write, dont think you can find a readymade code for that. But You need to use cron job, to automate a function to run at regular intervals in a unix machine. You can find more info on how to write a cron-job here. So you now, just need to write a web interface, which gets data from user and changes the rule according to the input(Which I think you can do it yourselves)

4
  • mysqldump doesn't work from the outside if your DB server is only available on localhost or some RFC 1918 address. Jun 14, 2012 at 9:23
  • See my answer to stackoverflow.com/a/11031535/219640 if you REALLY need to do this with phpMyAdmin. Jun 14, 2012 at 10:56
  • 2
    Remove those wierd quotes if date complains about the format: : date “+\%Y-\%m-\%d” => date +\%Y-\%m-\%d Feb 11, 2013 at 15:12
  • Your "also check this" link is invalid or no longer exists. Jun 5, 2018 at 7:44
3

The Code Will be Like This :

    @echo off
    for /f "tokens=1" %%i in ('date /t') do set DATE_DOW=%%i
    for /f "tokens=2" %%i in ('date /t') do set DATE_DAY=%%i
    for /f %%i in ('echo %date_day:/=-%') do set DATE_DAY=%%i
    for /f %%i in ('time /t') do set DATE_TIME=%%i
    for /f %%i in ('echo %date_time::=-%') do set DATE_TIME=%%i
    "j:\xamppp\bin\mysqldump" -u root -p  --all-databases>j:\backupmysql\%DATE_DAY%_%DATE_TIME%_database.sql

and save it as .bat and u can run it from task scheduler

2

I wrote a quick script for this exact use-case, since I had no access to the console for mysqldump and therefore needed it myself:

Downloads: Github: phpmyadmin_sql_backup.py

Usage in your case:

./phpmyadmin_sql_backup.py "https://www.example.com/phpmyadmin_login_page" USERNAME PASSWORD --basename "" --prepend-date --prefix-format "spbk%y%m%d" --overwrite-existing -o OUTPUT_DIRECTORY

Hopefully it proves to be useful for others.

2
  • python script is not working, error line 66: invalid syntax
    – Jerry1
    Jul 14, 2016 at 12:21
  • Jerry1: You need to use Python 3 for this to work (as stated on the github page)
    – phoibos
    Jul 14, 2016 at 18:07
1

The best way to automate MySQL DB backup is to use some backup software in conjunction with phpmyadmin utility. The second way, often having an advantage of no extra payment and a disadvantage of uncontrolled security, is implementing some script with cron.

Personally, I prefer Handy Backup in addition to my phpMyAdmin. See the link to an article as an example. It is not hottest backup solution, but relatively cheap and very stable.

0

Create .bat file in a folder when you have admin rights. down here is a simple .bat file

cd "C:\XAMPP\mysql\bin"
mysqldump -hlocalhost -uroot ca > "D:\cash\bkcash\ca\db_%date:~-4,4%%date:~-10,2%%date:~7,2%_%time:~0,2%%time:~3,2%%time:~6,2%.sql"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.