Hello,
i want to backup all databases in my server every 4 hour,
any body can help me to solve this problm ?
thank you
i want to backup all databases in my server every 4 hour,
any body can help me to solve this problm ?
thank you
#!/bin/bash
# Add your backup dir location, password, mysql location and mysqldump location
DATE=$(date +%d-%m-%Y)
BACKUP_DIR="/backup/test-backup"
MYSQL_USER="root"
MYSQL_PASSWORD="***"
MYSQL=/usr/bin/mysql
MYSQLDUMP=/usr/bin/mysqldump
# To create a new directory into backup directory location
mkdir -p $BACKUP_DIR/$DATE
# get a list of databases
databases=`$MYSQL -u$MYSQL_USER -p$MYSQL_PASSWORD -e "SHOW DATABASES;" | grep -Ev "(Database|information_schema)"`
# dump each database in separate name
for db in $databases; do
echo $db
$MYSQLDUMP --force --opt --user=$MYSQL_USER -p$MYSQL_PASSWORD --databases $db | gzip > "$BACKUP_DIR/$DATE/$db.sql.gz"
done
#!/bin/bash
password="***"
date_format=`date +%d-%m-%Y`
mysqldump -u root -p [password] 2daygeek | gzip -9 > /backup/db/yourdbname$date_format.sql.gz
find /backup/db/test* -mtime +5 -exec rm {} \;
cron job for every 4 hour.
0 */4 * * * /bin/mysql_backup.sh
Hello mageshmn ,Hi hossein,
For your requirement you need to done this by shell script.
Create a file “mysql_backup.sh” on your server and put the below code. Assign the executable permission on your shell file. like 755
All database on cpanel server.
===============================
Code:#!/bin/bash # Add your backup dir location, password, mysql location and mysqldump location DATE=$(date +%d-%m-%Y) BACKUP_DIR="/backup/test-backup" MYSQL_USER="root" MYSQL_PASSWORD="***" MYSQL=/usr/bin/mysql MYSQLDUMP=/usr/bin/mysqldump # To create a new directory into backup directory location mkdir -p $BACKUP_DIR/$DATE # get a list of databases databases=`$MYSQL -u$MYSQL_USER -p$MYSQL_PASSWORD -e "SHOW DATABASES;" | grep -Ev "(Database|information_schema)"` # dump each database in separate name for db in $databases; do echo $db $MYSQLDUMP --force --opt --user=$MYSQL_USER -p$MYSQL_PASSWORD --databases $db | gzip > "$BACKUP_DIR/$DATE/$db.sql.gz" done
single database on cpanel server.
==================================
==========================Code:#!/bin/bash password="***" date_format=`date +%d-%m-%Y` mysqldump -u root -p [password] 2daygeek | gzip -9 > /backup/db/yourdbname$date_format.sql.gz find /backup/db/test* -mtime +5 -exec rm {} \; cron job for every 4 hour.
To run the shell file every 4 hour you need to set the cron job like below.
Code:0 */4 * * * /bin/mysql_backup.sh
Hello Yas ItHello
It is also simple to back up all of the databases on a server with command :
mysqldump --all-databases > all_databases.sql
But when restore full backups(files,logs and ...) cpanel and restore sql with "mysql -u root -p passwordroot < all_databases.sql" on another server all websites cannot connect to database but size databases in MySQL Databases is correct and login in to phpmyadmin
so, If I use my this shell This problem will be repeated?
Please help , thank you.
i was test with all databases.Hello
you testing with single database , i dump all databases!
Thread starter | Similar threads | Forum | Replies | Date |
---|---|---|---|---|
G | Automated Backups Converting Columns in Databases | Backups | 1 | |
![]() |
Backup error regarding databases | Backups | 3 | |
![]() |
Backup all MySQL Databases? | Backups | 15 | |
V | mysql databases (only) backup | Backups | 1 | |
S | System backup & databases | Backups | 4 |