Linux Backs up MySQL to a temporary path from Webmin

I tried to set up a scheduled task in Linux Ubuntu Server 12.04 (CronJob) to back up all my MySQL databases daily at midnight.

I installed the famous Webmin (a good web interface for managing web servers).

So my problem is: whenever the backup is done, the files are overwritten!

This means: the day before yesterday backup is lost, only the "Yesterday" backup is saved!

I tried something like setting a dynamic file path, for example:

/ var / www / mysqlbackups /% d-% m-% y

but I was not successful in this :(

Can anybody help me.

Thanks a lot of guys.

+7
source share
5 answers

I created a shell script (not for webmin). Put it in /etc/cron.daily.

The scripts back up the database (saves it as .gz) and then uploads its ssh to another server. For authorization. I install ssh keys, so no password is required. Backup files have a unique name, so you do not overwrite backup files.

Here's how you can create a file name inside a script:

now=`date +%Y%m%d_%H%M` dst_path=/var/local/backups filename="$dst_path/$database.$now.sql.gz" 

Then you should write a small script that deletes all backup files that are older than x days.

 #!/bin/sh # # Creates a backup of a MySQL databases and uses ssh (sFTP) to send if to another server # This script shouldbe called from the crontab PATH=/usr/sbin:/usr/bin:/sbin:/bin # MySQL user and password mysql_cmd=/opt/bitnami/mysql/bin/mysqldump mysql_usr=user_name mysql_pass=password # destination ssh dst_user=user_name dst_hostname=192.168.1.1 # Database to backup database=test # create timestamp now=`date +%Y%m%d_%H%M` # where we store the files dst_path=/var/local/backups # backup filename filename="$dst_path/$database.$now.sql.gz" dst_filename="$database.$now.sql.gz" # run backup $mysql_cmd -u $mysql_usr --password=$mysql_pass $database | gzip > $filename # upload to sever (ssh) scp $filename $dst_user@ $dst_hostname: 
+2
source

MySQL Database Server> Module Config> Select "Yes" to "Substitution backups in strftime?"

It works for me! :)

+12
source

You can use the dynamic path, but before you must include it in the module configuration:

 System > Filesystem Backup > Module Config > Do strftime substitution of backup destinations? > Yes 

(If you are not sure about the additional files, just click on the text โ€œResolve the replacement of backup destinations?โ€ In the configuration and the help will show you.)

+11
source

I had the same problem and solved like this:

From Server, select MySQL Database Server . Go to the Module Configuration (top left) and select Arrange replacement of destinations in the backup storage for Yes .

I use the format db_% d-% m-% Y.sql for backup. (Db_13-03-2013.sql)

+6
source

You can do it as follows

Webmin> MySQL Database Server> select database> database backup> file path in another backup option you can use> Command to start after backup Enter ======> mv file path / file file path / filename_date date +"%Y%m%d%H%M%S" .sql

0
source

Source: https://habr.com/ru/post/922905/