Pyinfra that deploy my LXD server.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

108 lines
2.3 KiB

9 months ago
7 months ago
7 months ago
7 months ago
7 months ago
9 months ago
9 months ago
  1. from pyinfra import host
  2. from pyinfra.operations import server, files, systemd, apt
  3. SUDO = True
  4. apt.packages(
  5. name='Install packages',
  6. packages=['borgbackup', 'borgmatic'],
  7. update=True,
  8. )
  9. files.directory(
  10. name='Ensure /var/backups/lxd exists',
  11. path='/var/backups/lxd',
  12. user='root',
  13. group='root',
  14. mode=700
  15. )
  16. if not host.fact.command('zfs list | grep exports || true'):
  17. server.shell(
  18. name='Create ZFS volume exports',
  19. commands=['zfs create backup/exports -o mountpoint=/var/backups/lxd']
  20. )
  21. if not host.fact.command('mount | grep exports || true'):
  22. server.shell(
  23. name='Mount backup/exports',
  24. commands=['zfs mount backup/exports || true'],
  25. )
  26. files.directory(
  27. name='Ensure /var/backups/databases exists',
  28. path='/var/backups/databases',
  29. user='root',
  30. group='root',
  31. mode=700
  32. )
  33. if not host.fact.command('zfs list | grep databases || true'):
  34. server.shell(
  35. name='Create ZFS volume databases',
  36. commands=['zfs create backup/databases -o mountpoint=/var/backups/databases']
  37. )
  38. if not host.fact.command('mount | grep databases || true'):
  39. server.shell(
  40. name='Mount backup/databases',
  41. commands=['zfs mount backup/databases || true'],
  42. )
  43. files.put(
  44. name='Push borgmatic config',
  45. src='files/borgmatic.yaml',
  46. dest='/etc/borgmatic/config.yaml',
  47. mode='600',
  48. user='root',
  49. group='root',
  50. )
  51. files.put(
  52. name='Push lxd-export script',
  53. src='files/lxd-export.sh',
  54. dest='/usr/local/bin/lxd-export.sh',
  55. user='root',
  56. group='root',
  57. mode='700',
  58. )
  59. files.put(
  60. name='Push lxd-databases script',
  61. src='files/lxd-databases.sh',
  62. dest='/usr/local/bin/lxd-databases.sh',
  63. user='root',
  64. group='root',
  65. mode='700',
  66. )
  67. files.put(
  68. name='Push borgmatic timer',
  69. src='files/borgmatic.timer',
  70. dest='/etc/systemd/system/borgmatic.timer',
  71. user='root',
  72. group='root',
  73. mode='644',
  74. )
  75. files.put(
  76. name='Push borgmatic service',
  77. src='files/borgmatic.service',
  78. dest='/etc/systemd/system/borgmatic.service',
  79. user='root',
  80. group='root',
  81. mode='644',
  82. )
  83. systemd.daemon_reload(
  84. name='Reload systemd',
  85. user_mode=False,
  86. )
  87. systemd.service(
  88. name='Enable borgmatic timer',
  89. service='borgmatic.timer',
  90. running=True,
  91. enabled=True,
  92. )