php 如何使用 phpmyadmin 自动备份数据库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6645818/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to automate database backup using phpmyadmin
提问by n92
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.
我目前正在使用 phpmyadmin 导出作为 sql 转储手动进行数据库备份,结果文件名将是 spbkYYMMDD(Y;year m:month D:day)。有什么方法可以自动化数据库备份,以便我定期获得 sql dump间隔和文件名应该相应地自动生成。你能解释一下逻辑吗?
采纳答案by Balanivash
Run crontab in unix shell and create the rule to launch process for creating database backup
在 unix shell 中运行 crontab 并创建规则以启动创建数据库备份的过程
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)
您只需编写 Web 界面,不要认为您可以为此找到现成的代码。但是您需要使用 cron 作业来自动执行在 unix 机器上定期运行的功能。您可以在此处找到有关如何编写 cron-job 的更多信息。所以你现在只需要写一个web界面,它从用户那里获取数据并根据输入改变规则(我认为你可以自己做)
回答by Mark Geek
The best way to automate MySQL DB backup is to use some backup software in conjunction with phpmyadminutility. The second way, often having an advantage of no extra payment and a disadvantage of uncontrolled security, is implementing some script with cron.
自动化 MySQL 数据库备份的最佳方法是将某些备份软件与phpmyadmin实用程序结合使用。第二种方式通常具有无需额外付款的优点和不受控制的安全性的缺点,是使用cron实现一些脚本。
Personally, I prefer Handy Backup in addition to my phpMyAdmin. See the link to an articleas an example. It is not hottest backup solution, but relatively cheap and very stable.
就个人而言,除了我的phpMyAdmin之外,我更喜欢 Handy Backup 。见链接的文章作为例子。它不是最热门的备份解决方案,但相对便宜且非常稳定。
回答by Zaman
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
并将其保存为 .bat,您可以从任务调度程序中运行它
回答by phoibos
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:
我为这个确切的用例编写了一个快速脚本,因为我无法访问控制台mysqldump
,因此我自己需要它:
Downloads:Github: phpmyadmin_sql_backup.py
下载: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.
希望它被证明对其他人有用。