80 lines
1.3 KiB

  1. #!/bin/bash
  2. ## REQUIRES lxc-scripts, lxc
  3. ##
  4. ## Backup lxc
  5. ##
  6. ln -sfv /opt/apps/lxc-scripts/etc/cron.hourly/* /etc/cron.hourly/
  7. ln -sfv /opt/apps/lxc-scripts/etc/cron.daily/* /etc/cron.daily/
  8. if ! grep ^BACKUP_LXC_PATH= /etc/default/lxc >/dev/null 2>&1; then
  9. echo "BACKUP_LXC_PATH=/var/backups/lxc" >> /etc/default/lxc
  10. fi
  11. if ! grep ^BACKUP_SNAPSHOT_PATH= /etc/default/datastore >/dev/null 2>&1; then
  12. echo "BACKUP_SNAPSHOT_PATH=/var/backups/snapshot" >> /etc/default/datastore
  13. fi
  14. ##
  15. ## Mirror dir's logrotate and rsyslog's entry
  16. ##
  17. mkdir -p /etc/mirror-dir
  18. cat <<EOF > /etc/mirror-dir/config.yml
  19. default:
  20. sources:
  21. - /etc
  22. - /opt
  23. - /root
  24. - /var/log
  25. - /var/lib/lxc
  26. - /home
  27. - /boot
  28. - /srv
  29. - /var/backups/lxc/latest
  30. /var/lib/lxc:
  31. exclude:
  32. - /*/rootfs
  33. EOF
  34. cat <<EOF > /etc/rsyslog.d/mirror-dir.conf
  35. if \$programname == 'mirror-dir' then {
  36. action(type="omfile" file="/var/log/mirror-dir.log")
  37. stop
  38. }
  39. EOF
  40. service rsyslog restart
  41. cat <<EOF > /etc/logrotate.d/mirror-dir.log
  42. /var/log/mirror-dir.log
  43. {
  44. weekly
  45. missingok
  46. dateext
  47. dateyesterday
  48. dateformat _%Y-%m-%d
  49. extension .log
  50. rotate 52
  51. compress
  52. delaycompress
  53. notifempty
  54. create 640 root root
  55. sharedscripts
  56. postrotate
  57. reload rsyslog >/dev/null 2>&1 || true
  58. endscript
  59. }
  60. EOF