官方介紹
html
文件狀態備份bash
在0.10.2中,添加了一項新功能,用於備份由file.managed和file.recurse狀態替換的文件。新功能稱爲備份模式。設置備份模式很容易,可是能夠在許多地方進行設置。ssh
能夠在minion配置文件中設置backup_mode:ide
backup_mode: minion
或者能夠爲每一個文件設置它:rest
/etc/ssh/sshd_config: file.managed: - source: salt://ssh/sshd_config - backup: minion
備份文件htm
文件將保存在名爲的目錄下的minion cachedir中 file_backup。文件將位於相對於它們在根文件系統下的位置,並附加時間戳。這應該使它們易於瀏覽。rem
與備份互動get
從0.17.0版開始,將能夠列出,還原和刪除之前建立的備份。it
清單io
能夠使用file.list_backups如下命令列出給定文件的備份:
# salt foo.bar.com file.list_backups /tmp/foo.txt foo.bar.com: ---------- 0: ---------- Backup Time: Sat Jul 27 2013 17:48:41.738027 Location: /var/cache/salt/minion/file_backup/tmp/foo.txt_Sat_Jul_27_17:48:41_738027_2013 Size: 13 1: ---------- Backup Time: Sat Jul 27 2013 17:48:28.369804 Location: /var/cache/salt/minion/file_backup/tmp/foo.txt_Sat_Jul_27_17:48:28_369804_2013 Size: 35
恢復中
恢復很容易使用file.restore_backup,只需傳遞路徑和找到的數字ID file.list_backups:
# salt foo.bar.com file.restore_backup /tmp/foo.txt 1 foo.bar.com: ---------- comment: Successfully restored /var/cache/salt/minion/file_backup/tmp/foo.txt_Sat_Jul_27_17:48:28_369804_2013 to /tmp/foo.txt result: True 爲了以防萬一,能夠file.list_backups再次備份現有文件,能夠 再次運行: # salt foo.bar.com file.list_backups /tmp/foo.txt foo.bar.com: ---------- 0: ---------- Backup Time: Sat Jul 27 2013 18:00:19.822550 Location: /var/cache/salt/minion/file_backup/tmp/foo.txt_Sat_Jul_27_18:00:19_822550_2013 Size: 53 1: ---------- Backup Time: Sat Jul 27 2013 17:48:41.738027 Location: /var/cache/salt/minion/file_backup/tmp/foo.txt_Sat_Jul_27_17:48:41_738027_2013 Size: 13 2: ---------- Backup Time: Sat Jul 27 2013 17:48:28.369804 Location: /var/cache/salt/minion/file_backup/tmp/foo.txt_Sat_Jul_27_17:48:28_369804_2013 Size: 35
注意
因爲未運行任何狀態,所以還原文件不會觸發對該文件的任何監視。所以,若是要還原服務的配置文件,則可能仍須要運行service.restart。
刪除中
能夠使用file.delete_backup如下方法刪除備份:
# salt foo.bar.com file.delete_backup /tmp/foo.txt 0 foo.bar.com: ---------- comment: Successfully removed /var/cache/salt/minion/file_backup/tmp/foo.txt_Sat_Jul_27_18:00:19_822550_2013 result: True