diff --git a/backup.py b/backup.py index e51e22885..93bd0da37 100644 --- a/backup.py +++ b/backup.py @@ -43,6 +43,8 @@ def backup(): # Create directory try: os.listdir(backup_dir) except OSError: os.makedirs(backup_dir) + os.system('chmod 755 /home/yunohost.backup /home/yunohost.backup/tmp') + os.system('chown -hR admin: %s' % backup_dir) # Run hook hook_callback('backup', [backup_dir]) diff --git a/hooks/backup/11-system_mysql b/hooks/backup/11-system_mysql new file mode 100644 index 000000000..e5ff07c52 --- /dev/null +++ b/hooks/backup/11-system_mysql @@ -0,0 +1,7 @@ +#!/bin/bash + +backup_dir="$1/mysql" +mkdir -p $backup_dir + +mysqlpwd=$(sudo cat /etc/yunohost/mysql) +sudo mysqldump -uroot -p"$mysqlpwd" mysql > $backup_dir/mysql.sql diff --git a/hooks/backup/14-system_ssowat b/hooks/backup/14-system_ssowat new file mode 100644 index 000000000..f642ea243 --- /dev/null +++ b/hooks/backup/14-system_ssowat @@ -0,0 +1,6 @@ +#!/bin/bash + +backup_dir="$1/ssowat" +mkdir -p $backup_dir + +sudo cp -a /etc/ssowat/* $backup_dir/ diff --git a/hooks/backup/17-system_home b/hooks/backup/17-system_home new file mode 100644 index 000000000..13414a755 --- /dev/null +++ b/hooks/backup/17-system_home @@ -0,0 +1,6 @@ +#!/bin/bash + +backup_dir="$1/home" +mkdir -p $backup_dir + +sudo rsync -a --exclude='/yunohost*' /home/ $backup_dir/ diff --git a/hooks/backup/20-system_yunohost b/hooks/backup/20-system_yunohost new file mode 100644 index 000000000..305c82ed7 --- /dev/null +++ b/hooks/backup/20-system_yunohost @@ -0,0 +1,6 @@ +#!/bin/bash + +backup_dir="$1/yunohost" +mkdir -p $backup_dir + +sudo cp -a /etc/yunohost/* $backup_dir/ diff --git a/hooks/backup/23-system_mail b/hooks/backup/23-system_mail new file mode 100644 index 000000000..ad1cf5ae5 --- /dev/null +++ b/hooks/backup/23-system_mail @@ -0,0 +1,6 @@ +#!/bin/bash + +backup_dir="$1/mail" +mkdir -p $backup_dir + +sudo cp -a /var/mail/* $backup_dir/ diff --git a/hooks/backup/26-system_xmpp b/hooks/backup/26-system_xmpp new file mode 100644 index 000000000..bfa138196 --- /dev/null +++ b/hooks/backup/26-system_xmpp @@ -0,0 +1,7 @@ +#!/bin/bash + +backup_dir="$1/xmpp" +mkdir -p $backup_dir/{etc,var} + +sudo cp -a /etc/metronome/* $backup_dir/etc/ +sudo cp -a /var/lib/metronome/* $backup_dir/var/ diff --git a/hooks/backup/29-system_nginx b/hooks/backup/29-system_nginx new file mode 100644 index 000000000..9d1bc5b0b --- /dev/null +++ b/hooks/backup/29-system_nginx @@ -0,0 +1,6 @@ +#!/bin/bash + +backup_dir="$1/nginx" +mkdir -p $backup_dir + +sudo cp -a /etc/nginx/conf.d/* $backup_dir/ diff --git a/hooks/backup/32-system_cron b/hooks/backup/32-system_cron new file mode 100644 index 000000000..b529b0216 --- /dev/null +++ b/hooks/backup/32-system_cron @@ -0,0 +1,6 @@ +#!/bin/bash + +backup_dir="$1/cron" +mkdir -p $backup_dir + +sudo cp -a /etc/cron.d/yunohost* $backup_dir/ diff --git a/hooks/backup/5-system_ldap b/hooks/backup/5-system_ldap new file mode 100644 index 000000000..88d824b60 --- /dev/null +++ b/hooks/backup/5-system_ldap @@ -0,0 +1,9 @@ +#!/bin/bash + +backup_dir="$1/ldap" +mkdir -p $backup_dir + +sudo cp -a /etc/ldap/slapd.conf $backup_dir/ +slapcat -l $backup_dir/slapcat.ldif.raw +egrep -v "^entryCSN:" < $backup_dir/slapcat.ldif.raw > $backup_dir/slapcat.ldif +rm -f $backup_dir/slapcat.ldif.raw diff --git a/hooks/backup/8-system_ssh b/hooks/backup/8-system_ssh new file mode 100644 index 000000000..bd5db66ac --- /dev/null +++ b/hooks/backup/8-system_ssh @@ -0,0 +1,6 @@ +#!/bin/bash + +backup_dir="$1/ssh" +mkdir -p $backup_dir + +sudo cp -a /etc/ssh/* $backup_dir/ diff --git a/hooks/restore/11-system_mysql b/hooks/restore/11-system_mysql new file mode 100644 index 000000000..28db51483 --- /dev/null +++ b/hooks/restore/11-system_mysql @@ -0,0 +1,7 @@ +#!/bin/bash + +backup_dir="$1/mysql" + +mysqlpwd=$(sudo cat /etc/yunohost/mysql) +sudo mysql -uroot -p"$mysqlpwd" mysql < $backup_dir/mysql.sql +sudo mysqladmin flush-privileges -p"$mysqlpwd" diff --git a/hooks/restore/14-system_ssowat b/hooks/restore/14-system_ssowat new file mode 100644 index 000000000..4c00a5ab1 --- /dev/null +++ b/hooks/restore/14-system_ssowat @@ -0,0 +1,5 @@ +#!/bin/bash + +backup_dir="$1/ssowat" + +sudo cp -a $backup_dir/* /etc/ssowat/ diff --git a/hooks/restore/17-system_home b/hooks/restore/17-system_home new file mode 100644 index 000000000..d097dad08 --- /dev/null +++ b/hooks/restore/17-system_home @@ -0,0 +1,5 @@ +#!/bin/bash + +backup_dir="$1/home" + +sudo cp -a $backup_dir/* /home/ diff --git a/hooks/restore/20-system_yunohost b/hooks/restore/20-system_yunohost new file mode 100644 index 000000000..bb23a2ddd --- /dev/null +++ b/hooks/restore/20-system_yunohost @@ -0,0 +1,11 @@ +#!/bin/bash + +backup_dir="$1/yunohost" + +sudo cp -a $backup_dir/* /etc/yunohost/ +sudo yunohost app ssowatconf +sudo yunohost firewall reload + +# Reload interface name +sudo rm /etc/yunohost/interface +sudo apt-get install --reinstall -y yunohost-config-others diff --git a/hooks/restore/23-system_mail b/hooks/restore/23-system_mail new file mode 100644 index 000000000..28eafc332 --- /dev/null +++ b/hooks/restore/23-system_mail @@ -0,0 +1,9 @@ +#!/bin/bash + +backup_dir="$1/mail" + +sudo cp -a $backup_dir/* /var/mail/ + +# Restart services to use migrated certs +sudo service postfix restart +sudo service dovecot restart diff --git a/hooks/restore/26-system_xmpp b/hooks/restore/26-system_xmpp new file mode 100644 index 000000000..c9677f944 --- /dev/null +++ b/hooks/restore/26-system_xmpp @@ -0,0 +1,9 @@ +#!/bin/bash + +backup_dir="$1/xmpp" + +sudo cp -a $backup_dir/etc/* /etc/metronome/ +sudo cp -a $backup_dir/var/* /var/lib/metronome/ + +# Restart to apply new conf and certs +sudo service metronome restart diff --git a/hooks/restore/29-system_nginx b/hooks/restore/29-system_nginx new file mode 100644 index 000000000..ca72c76c1 --- /dev/null +++ b/hooks/restore/29-system_nginx @@ -0,0 +1,8 @@ +#!/bin/bash + +backup_dir="$1/nginx" + +sudo cp -a $backup_dir/* /etc/nginx/conf.d/ + +# Restart to use new conf and certs +sudo service nginx restart diff --git a/hooks/restore/32-system_cron b/hooks/restore/32-system_cron new file mode 100644 index 000000000..c237157c7 --- /dev/null +++ b/hooks/restore/32-system_cron @@ -0,0 +1,8 @@ +#!/bin/bash + +backup_dir="$1/cron" + +sudo cp -a $backup_dir/* /etc/cron.d/ + +# Restart just in case +sudo service cron restart diff --git a/hooks/restore/5-system_ldap b/hooks/restore/5-system_ldap new file mode 100644 index 000000000..58ca04ea9 --- /dev/null +++ b/hooks/restore/5-system_ldap @@ -0,0 +1,38 @@ +#!/bin/bash + +backup_dir="$1/ldap" + +if [ -z "$2" ]; then + + # We need to execute this script as root, since the ldap + # service will be shut down during the operation (and sudo + # won't be available) + sudo bash $(pwd)/$0 $1 sudoed + +else + service slapd stop + + # Backup old configuration + mv /var/lib/ldap /var/lib/ldap.old + + # Recreate new DB folder + mkdir /var/lib/ldap + chown openldap: /var/lib/ldap + chmod go-rwx /var/lib/ldap + + # Restore LDAP configuration (just to be sure) + cp -a $backup_dir/slapd.conf /etc/ldap/slapd.conf + + # Regenerate the configuration + rm -rf /etc/ldap/slapd.d/* + slaptest -u -f /etc/ldap/slapd.conf -F /etc/ldap/slapd.d + cp -rfp /var/lib/ldap.old/DB_CONFIG /var/lib/ldap + + # Import the database + slapadd -l $backup_dir/slapcat.ldif + + # Change permissions and restart slapd + chown openldap: /var/lib/ldap/* + service slapd start + rm -rf /var/lib/ldap.old +fi diff --git a/hooks/restore/8-system_ssh b/hooks/restore/8-system_ssh new file mode 100644 index 000000000..8f3d3b671 --- /dev/null +++ b/hooks/restore/8-system_ssh @@ -0,0 +1,6 @@ +#!/bin/bash + +backup_dir="$1/ssh" + +sudo cp -a $backup_dir/* /etc/ssh/ +sudo service ssh restart