Commit 0054135b authored by HongzheWang's avatar HongzheWang

matomo-tutorial:Add backup function

parent 33ff2ac8
......@@ -15,4 +15,8 @@
[template-matomo-instance]
filename = matomo-instance.cfg.in
md5sum = d41d8cd98f00b204e9800998ecf8427e
md5sum = 2183607e3c22bc57d3898742ea0c1ef5
[template-matomo-backup.sh]
filename = matomo-backup.sh.in
md5sum = fb29ad59813ef62c3f5934d4a0d90e14
#!/bin/sh
set -e
set -x
#checkout if directory and matomo resources exist
if [ ! -d {{ parameter_dict['document-root'] }}/matomo/config ]; then
exit 1;
fi
if [ ! -f {{ parameter_dict['document-root'] }}/matomo/config/config.ini.php ]; then
exit 0;
fi
trap 'rm -rf "$TMPFILE"' EXIT TERM INT
#we reserve backup folder in a month
{{ parameter_dict['find-bin'] }}/bin/find {{ parameter_dict['dir-backup'] }} -mtime +30 -type d |{{ parameter_dict['find-bin'] }}/bin/xargs rm -rf
#backup
TMPFILE=$(mktemp -d -p "{{ parameter_dict['dir-backup'] }}")
{{ php_bin }} {{ parameter_dict['document-root'] }}/matomo/console plugin:list > $TMPFILE/plugins_list
cp -rf {{ parameter_dict['document-root'] }}/matomo/config $TMPFILE/config
cp -rf {{ parameter_dict['document-root'] }}/matomo/plugins $TMPFILE/plugins
#check if copy-action finish well
if test ! -z "$({{ parameter_dict['diff-bin'] }}/bin/diff -r $TMPFILE/config {{ parameter_dict['document-root'] }}/matomo/config)"; then
exit 1
fi
if test ! -z "$({{ parameter_dict['diff-bin'] }}/bin/diff -r $TMPFILE/plugins {{ parameter_dict['document-root'] }}/matomo/plugins)"; then
exit 1
fi
#check if the file plugins_list has been created
if [ ! -f $TMPFILE/plugins_list ]; then
exit 1
fi
#if all things go well, change the name of folder with date now
if [ -d $TMPFILE ]; then
mv -f $TMPFILE {{ parameter_dict['dir-backup'] }}/`date +%m-%d-%Y-%T`
fi
exit 0
# parameters required by the configuration instance
[instance-parameter]
matomo = ${:document-root}
dir-backup = ${directory:backup}
find-bin = {{ findutils_location }}
diff-bin = {{ diffutils_location }}
[matomo-backup.sh]
recipe = slapos.recipe.template:jinja2
url = {{ matomo_backup_sh }}
output = ${directory:scripts}/matomo-backup
context =
section parameter_dict instance-parameter
key php_bin php-bin:wrapper-path
......@@ -6,6 +6,8 @@ extends =
# "slapos" stack describes basic things needed for 99.9% of SlapOS Software
../../stack/slapos.cfg
../../component/diffutils/buildout.cfg
parts =
# Call installation of slapos.cookbook egg defined in stack/slapos.cfg (needed
# in 99,9% of Slapos Software Releases)
......@@ -30,7 +32,7 @@ archive-root = matomo
# Without it the instance-matomo.cfg file will not be executed
[custom-application-deployment]
path = ${template-matomo-instance:output}
part-list =
part-list = matomo-backup.sh
db-name = matomo
db-user = matomo
db-password = 12345678
......@@ -40,3 +42,11 @@ recipe = slapos.recipe.template:jinja2
url = ${:_profile_base_location_}/${:filename}
output = ${buildout:directory}/instance-matomo.cfg
context =
key findutils_location findutils:location
key diffutils_location diffutils:location
key php_location apache-php:location
key matomo_backup_sh template-matomo-backup.sh:target
# download matomo-backup.sh.in
[template-matomo-backup.sh]
<= matomo-download
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment