There are servers those don't have any hosting control panels and hosting websites and databases in it. Here I am describing a simple way to set up an auto backup solution for the databases configured on the server.
Please follow the steps below:
- Create a directory to store the backup files on the server. Here we are using /backup.
- Create a small shell script with the DB username, password, backup location, backup name etc.
vi dbbackup.sh
mysqldump -u root -pdbpass dbname>/backup/dbname-`date '+%Y-%m-%d'`.sql
Here, you need to replace the username with the actual username and also provide the correct DB name and password instead of 'dbpass'. - Now we need to make it as an executable file:
chmod +x dbbackup.sh
- It is better to run it using a cronjob in order to take automatic backups.
#crontab -e
0 0 * * * sh /dbbackup.sh
This will run once in a day. If you need to take more backups a day, you can adjust the cronjob accordingly.