We are happy to announce that Vesta is back under active development as of 25 February 2024. We are working on v1 candidate and expect to engage more with the community over the coming months. We are committed to open source, and we encourage contributors to help us build the future of Vesta.
Auto backup mysql
Auto backup mysql
Hello,
How do I run an automatic copy of MySQL performed every 60 minutes? I could ask for a command to cron?
How do I run an automatic copy of MySQL performed every 60 minutes? I could ask for a command to cron?
-
- Collaborator
- Posts: 783
- Joined: Mon May 11, 2015 8:43 am
- Contact:
- Os: CentOS 6x
- Web: apache + nginx
Re: Auto backup mysql
You can use this bash script with cronjob:
Code: Select all
#!/bin/bash
# Database credentials
user="DB_USERNAME"
password="DB_PASSWORD"
host="localhost"
db_name="DB_NAME"
# Other options
backup_path="/home/username/web/youdomain/public_html/backup"
date=$(date +"%d-%b-%Y")
# Set default file permissions
umask 177
# Dump database into SQL file
mysqldump --user=$user --password=$password --host=$host $db_name | gzip > $backup_path/$db_name-$date.sql.gz
# Delete files older than 30 days
find $backup_path/* -mtime +30 -exec rm {} \;
Re: Auto backup mysql
Thank you. How can i add this to crontab?
In terminal: crontab -e and paste your code?
In terminal: crontab -e and paste your code?
-
- Collaborator
- Posts: 783
- Joined: Mon May 11, 2015 8:43 am
- Contact:
- Os: CentOS 6x
- Web: apache + nginx
Re: Auto backup mysql
Create a file: backup.shnorthwest wrote:Thank you. How can i add this to crontab?
In terminal: crontab -e and paste your code?
in crontab -e:
0 * * * * bash /home/username/backup.sh
Re: Auto backup mysql
Don't forget:tjebbeke wrote: Create a file: backup.sh
chmod +x backup.sh
..why we need bash? simple /path/to/backup.sh ?
Re: Auto backup mysql
If you don't want to receive e-mail notification, add after .sh:tjebbeke wrote: 0 * * * * bash /home/username/backup.sh
>/dev/null 2>&1
Re: Auto backup mysql
I am trying to implement this but just keep getting errors. Can anyone help me figure it out? I have little knowledge so am stuck.
: octal number out of ranges-#####/public_html/backup/backup.sh: line 11: umask: 177
: No such file or directorys-#######/public_html/backup/backup.sh: line 13: /home/admin/web/######/public_html/backup
' (0) when trying to connectUnknown MySQL server host 'localhost
: octal number out of ranges-#####/public_html/backup/backup.sh: line 11: umask: 177
: No such file or directorys-#######/public_html/backup/backup.sh: line 13: /home/admin/web/######/public_html/backup
' (0) when trying to connectUnknown MySQL server host 'localhost
-
- Collaborator
- Posts: 783
- Joined: Mon May 11, 2015 8:43 am
- Contact:
- Os: CentOS 6x
- Web: apache + nginx
Re: Auto backup mysql
What is your OS? Have you created the 'backup' dir in /home/admin/web/######/public_html ?waynebr76 wrote:I am trying to implement this but just keep getting errors. Can anyone help me figure it out? I have little knowledge so am stuck.
: octal number out of ranges-#####/public_html/backup/backup.sh: line 11: umask: 177
: No such file or directorys-#######/public_html/backup/backup.sh: line 13: /home/admin/web/######/public_html/backup
' (0) when trying to connectUnknown MySQL server host 'localhost
Re: Auto backup mysql
Hi I am using Ubuntu Linux 14.04.2, the directory has been created and I tested it using mkdir and it says it exists.
Re: Auto backup mysql
- Check path in cron
- Check sh script - exutable or not?
mkdir /path/to/directory
chmod +x /path/to/script.sh
Add in cron.
PS: Don't forget, if you run this under user (not root), simple user will have ssh (nologin don't work there) or have right to sudo your script.
- Check sh script - exutable or not?
mkdir /path/to/directory
chmod +x /path/to/script.sh
Add in cron.
PS: Don't forget, if you run this under user (not root), simple user will have ssh (nologin don't work there) or have right to sudo your script.