To create a full backup of your store over SSH with a bash script please login via the terminal and in the root of your store create a file called "backup.sh" with the following content.
#!/bin/sh
DBSERVER=XXX
DATABASE=XXX
USERNAME=XXX
PASSWORD=XXX
SQLFILE=${DATABASE}.sql
BACKUPFILE=full_ssh_backup_`date +"%d%b%y-%H%M%S"`.zip
echo "Creating MySQL dump ${SQLFILE}."
mysqldump --no-create-db=true -h ${DBSERVER} -u ${USERNAME} --password=${PASSWORD} ${DATABASE} > ${SQLFILE}
echo "Creating compressed archive of store files and ${SQLFILE}."
zip -rq ${BACKUPFILE} --exclude=${BACKUPFILE} --exclude=backup/* --exclude=images/cache/* --exclude=cache/* ./
echo "Backup created please download it from the 'Maintenance' > 'Backup' section of your admin control panel."
rm -rf ${SQLFILE}
mv ${BACKUPFILE} ./backup/${BACKUPFILE}
du -h ./backup/${BACKUPFILE}
Replace the red XXX values with your MySQL details and save this file to your server. To execute it via command line just type the following command:
./backup.sh
!!IMPORTANT SECURITY NOTICE!!
This file must not be accessible via a browser URL! To protect it edit your .htaccess file so that there is a section that looks like this:
## File Security
Order Allow,Deny
Deny from all
Alternatively (or aswell as) please remove the "PASSWORD" value and change the mysqldump command so that it prompts for password on eack backup like this:
mysqldump --no-create-db=true -h ${DBSERVER} -u ${USERNAME} -p ${DATABASE} > ${SQLFILE}
Scheduling Backups
You could also create a cron job to execute this file daily.
Comments
0 comments
Please sign in to leave a comment.