Backup a website using bash script.

I needed to complete a routine backup of my development websites on my home server. This was pretty easily completed by daily by a bash script.

Here is a simple script that backs up the database and all the files.

For the example below I’m using Maria DB 10.5 and my project files are located /home/projects/domains/websiteroot. This will be different depending on your setup.

/backup was is an external hard drive that was mounted.

now=$(date +"%d-%m-%Y")
echo "SQL BACKUP: Filename : /backup/projects-${now}.sql.gz"
mysqldump -u dbuser -p{password} staging | gzip > /backup/projects-${now}.sql.gz
cd /home/projects/domains/websiteroot
tar zcvf /backup/projects-${now}.tar.gz *


Common Gotya:

In mysqldump there is no space between -p and the password.
Eg -p{password} not -p {password}


Leave a Reply

Your email address will not be published. Required fields are marked *