backup_mode.rst 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. .. _file-state-backups:
  2. ==================
  3. File State Backups
  4. ==================
  5. In 0.10.2 a new feature was added for backing up files that are replaced by
  6. the file.managed and file.recurse states. The new feature is called the backup
  7. mode. Setting the backup mode is easy, but it can be set in a number of
  8. places.
  9. The backup_mode can be set in the minion config file:
  10. .. code-block:: yaml
  11. backup_mode: minion
  12. Or it can be set for each file:
  13. .. code-block:: yaml
  14. /etc/ssh/sshd_config:
  15. file.managed:
  16. - source: salt://ssh/sshd_config
  17. - backup: minion
  18. Backed-up Files
  19. ===============
  20. The files will be saved in the minion cachedir under the directory named
  21. ``file_backup``. The files will be in the location relative to where they
  22. were under the root filesystem and be appended with a timestamp. This should
  23. make them easy to browse.
  24. Interacting with Backups
  25. ========================
  26. Starting with version 0.17.0, it will be possible to list, restore, and delete
  27. previously-created backups.
  28. Listing
  29. -------
  30. The backups for a given file can be listed using :mod:`file.list_backups
  31. <salt.modules.file.list_backups>`:
  32. .. code-block:: bash
  33. # salt foo.bar.com file.list_backups /tmp/foo.txt
  34. foo.bar.com:
  35. ----------
  36. 0:
  37. ----------
  38. Backup Time:
  39. Sat Jul 27 2013 17:48:41.738027
  40. Location:
  41. /var/cache/salt/minion/file_backup/tmp/foo.txt_Sat_Jul_27_17:48:41_738027_2013
  42. Size:
  43. 13
  44. 1:
  45. ----------
  46. Backup Time:
  47. Sat Jul 27 2013 17:48:28.369804
  48. Location:
  49. /var/cache/salt/minion/file_backup/tmp/foo.txt_Sat_Jul_27_17:48:28_369804_2013
  50. Size:
  51. 35
  52. Restoring
  53. ---------
  54. Restoring is easy using :mod:`file.restore_backup
  55. <salt.modules.file.restore_backup>`, just pass the path and the numeric id
  56. found with :mod:`file.list_backups <salt.modules.file.list_backups>`:
  57. .. code-block:: bash
  58. # salt foo.bar.com file.restore_backup /tmp/foo.txt 1
  59. foo.bar.com:
  60. ----------
  61. comment:
  62. Successfully restored /var/cache/salt/minion/file_backup/tmp/foo.txt_Sat_Jul_27_17:48:28_369804_2013 to /tmp/foo.txt
  63. result:
  64. True
  65. The existing file will be backed up, just in case, as can be seen if
  66. :mod:`file.list_backups <salt.modules.file.list_backups>` is run again:
  67. .. code-block:: bash
  68. # salt foo.bar.com file.list_backups /tmp/foo.txt
  69. foo.bar.com:
  70. ----------
  71. 0:
  72. ----------
  73. Backup Time:
  74. Sat Jul 27 2013 18:00:19.822550
  75. Location:
  76. /var/cache/salt/minion/file_backup/tmp/foo.txt_Sat_Jul_27_18:00:19_822550_2013
  77. Size:
  78. 53
  79. 1:
  80. ----------
  81. Backup Time:
  82. Sat Jul 27 2013 17:48:41.738027
  83. Location:
  84. /var/cache/salt/minion/file_backup/tmp/foo.txt_Sat_Jul_27_17:48:41_738027_2013
  85. Size:
  86. 13
  87. 2:
  88. ----------
  89. Backup Time:
  90. Sat Jul 27 2013 17:48:28.369804
  91. Location:
  92. /var/cache/salt/minion/file_backup/tmp/foo.txt_Sat_Jul_27_17:48:28_369804_2013
  93. Size:
  94. 35
  95. .. note::
  96. Since no state is being run, restoring a file will not trigger any watches
  97. for the file. So, if you are restoring a config file for a service, it will
  98. likely still be necessary to run a ``service.restart``.
  99. Deleting
  100. --------
  101. Deleting backups can be done using :mod:`file.delete_backup
  102. <salt.modules.file.delete_backup>`:
  103. .. code-block:: bash
  104. # salt foo.bar.com file.delete_backup /tmp/foo.txt 0
  105. foo.bar.com:
  106. ----------
  107. comment:
  108. Successfully removed /var/cache/salt/minion/file_backup/tmp/foo.txt_Sat_Jul_27_18:00:19_822550_2013
  109. result:
  110. True