Jump to content

ISO - Prestashop 1.7 Back Up Module


Recommended Posts

Hi,

I am looking for a module that will back up my Prestashop files and database. If not a module a cron job would be useful if instructions. I just need it to back up at least once per day and on the third day delete day one back up to conserve space. When I need to retrieve back up it would be with a click of a button. Thanks in advance!

Link to comment
Share on other sites

Here is how I run a database and file backup of a PrestaShop production installation on a Linux host every day.

This keeps one copy of the backup on the Linux host. The copy is overwritten on every run. I have set up a computer on my local network to every morning download a copy of the backup from the Linux host and save the copy to an archive on the local network. I also use the backups on the Linux host to copy the production installation to my local Linux desktop for offline test and development purposes.

This is as simple as it gets and works fine in my use, but there is always room for improvement. For example now the file backup unnecessary includes PrestaShop's cache and log directories that don't really have to backed up. Also, the shop is in maintenance mode during the backup process to minimize the change of errors in data integrity. A break of a minute in availability is probably acceptable on a low volume shop that is seldom used at 4:00 AM, like mine, but might be unacceptable on a high volume shop if it causes loses of sales.

A line in my crontab on the Linux host that activates the backup procedure at 4:00 AM every day:
0 4 * * * /home/xxxxxxx/acps/utils/prod/sh/cronBackup.sh

The shell script that runs all the commands.
File 1: /home/xxxxxx/acps/utils/prod/sh/cronBackup.sh

#!/usr/bin/env bash

# Begin maintenance mode
mysql --defaults-file=/home/xxxxxx/acps/utils/prod/mysql-opts < /home/xxxxxx/acps/utils/prod/sql/disableShop.sql;

# Dump database to a SQL file
mysqldump --defaults-file=/home/xxxxxx/acps/utils/prod/mysql-opts --opt --databases xxxxxx_acpp > /home/xxxxxx/acps/tmp/prod.acpp.sql;

# Concatenate helper SQL in front and after the dumped SQL
cat /home/xxxxxx/acps/utils/prod/sql/presqldump.sql /home/xxxxxx/acps/tmp/prod.acpp.sql /home/xxxxxx/acps/utils/prod/sql/postsqldump.sql > /home/xxxxxx/acps/tmp/prod.acps.sql;

# Remove the dumped SQL file
rm /home/xxxxxx/acps/tmp/prod.acpp.sql;

# Compress the concatenated SQL file
cd /home/xxxxxx/acps/tmp; tar -czPf prod.acps.sql.tgz prod.acps.sql;

# Remove the contatenated SQL file
rm /home/xxxxxx/acps/tmp/prod.acps.sql;

# Compress all PrestaShop's files
cd /home/xxxxxx/domains/xxxxxx.com/public_html; tar -czPf /home/xxxxxx/acps/tmp/prod.acps.files.tgz .;

# End maintenance mode
mysql --defaults-file=/home/xxxxxx/acps/utils/prod/mysql-opts < /home/xxxxxx/acps/utils/prod/sql/enableShop.sql;

 

MySQL user credentials.

File 2: /home/xxxxxx/acps/utils/prod/mysql-opts

[mysql]
host=127.0.0.1
database=xxxxxx_acpp
user=dbuser
password=dbpass

[mysqldump]
user=dbuser
password=dbpass
host=127.0.0.1

 

Activate maintenance mode so no new transactions take place during the backup.

File 3: /home/xxxxxx/acps/utils/prod/sql/disableShop.sql

UPDATE ps_configuration SET value = 0 WHERE name='PS_SHOP_ENABLE';

 

Contents of file 4 are concatenated in front of the DB dump. This helps import the data in case you need to restore a backup or want to copy the data to an other PrestaShop instance for example for test and development use.

File 4: /home/xxxxxx/acps/utils/prod/sql/presqldump.sql

SET AUTOCOMMIT = 0;
SET FOREIGN_KEY_CHECKS=0;

Contents of file 5 are concatenated in the end of the DB dump.

File 5: /home/xxxxxx/acps/utils/prod/sql/postsqldump.sql

SET FOREIGN_KEY_CHECKS = 1;
COMMIT;
SET AUTOCOMMIT = 1;

 

End maintenance mode.

File 6: /home/xxxxxx/acps/utils/prod/sql/enableShop.sql

UPDATE ps_configuration SET value = 1 WHERE name='PS_SHOP_ENABLE';

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...