minion端备份



说明:

   正常情况下是不需要在minion端对文件进行备份的,但是为了有备无患,对于一些重要的文件还是进行备份比较好



备份方法:

master端:
[root@dbm133 ~]# cat /srv/salt/web/httpd/conf.sls
/tmp/scj/file1: 
  file.managed:
    - source: salt://files/test.txt
    - backup: minion                   ##backup函数,值为minion
##文件中多了一个函数backup,后面跟的值是minion,意思是说这个文件在minion中备份一份,备份文件名为 原文件名+时间,备份位置在/var/cache/salt/minion/file_backup



推送数据:

master端:
salt '*' state.sls web.httpd.conf          ##注,多修改几次salt://files/test.txt文件,多运行几次

minion端:
[root@dbm132 file_backup]# pwd
/var/cache/salt/minion/file_backup        ##备份文件目录
[root@dbm132 file_backup]# tree
.
└── tmp
    └── scj
        ├── file1_Thu_Jul_23_11:56:27_143271_2015
        ├── file1_Thu_Jul_23_13:57:52_087916_2015
        └── file1_Thu_Jul_23_13:58:24_445022_2015

2 directories, 3 files
##由tree目录结构发现,在/var/cache/salt/minion/file_backup备份目录下面也有一个/tmp/scj/目录,就是原文件的父目录,且备份文件为 原文件名+时间
##注意/var/cache/salt/minion/这个目录##
[root@dbm132 base]# pwd
/var/cache/salt/minion/files/base
[root@dbm132 base]# ll
total 16
drwx------ 3 root root 4096 Jul 20 15:40 httpd
-rw------- 1 root root   45 Jul 21 10:37 top.sls
drwx------ 2 root root 4096 Jul 21 10:37 user
drwx------ 3 root root 4096 Jul 20 14:43 web
##minion端会把master端/srv/salt目录下的所有配置管理文件同步到本地/var/cache/salt/minion/files/base目录



恢复方法:

master端:

##查看备份信息:
[root@dbm133 ~]# salt 'zszz_192.168.186.132' file.list_backups /tmp/scj/file1
zszz_192.168.186.132:
    ----------
    0:
        ----------
        Backup Time:
            Thu Jul 23 2015 13:58:24.445022
        Location:
            /var/cache/salt/minion/file_backup/tmp/scj/file1_Thu_Jul_23_13:58:24_445022_2015
        Size:
            111
    1:
        ----------
        Backup Time:
            Thu Jul 23 2015 13:57:52.087916
        Location:
            /var/cache/salt/minion/file_backup/tmp/scj/file1_Thu_Jul_23_13:57:52_087916_2015
        Size:
            110
    2:
        ----------
        Backup Time:
            Thu Jul 23 2015 11:56:27.143271
        Location:
            /var/cache/salt/minion/file_backup/tmp/scj/file1_Thu_Jul_23_11:56:27_143271_2015
        Size:
            0
##返回备份序号,时间,位置,大小 
           
##恢复:当文件改错后,我们可以用备份文件回退    
[root@dbm133 ~]# salt 'zszz_192.168.186.132' file.restore_backup /tmp/scj/file1 2
zszz_192.168.186.132:
    ----------
    comment:
        Successfully restored /var/cache/salt/minion/file_backup/tmp/scj/file1_Thu_Jul_23_13:58:24_445022_2015 to /tmp/scj/file1
    result:
        True
##指定回退的原文件名与想要回退的序列号,回退的序列号可以根据时间来定
        
##删除:删除不需要的备份文件
[root@dbm133 ~]# salt 'zszz_192.168.186.132' file.delete_backup /tmp/scj/file1 4
zszz_192.168.186.132:
    ----------
    comment:
        Successfully removed /var/cache/salt/minion/file_backup/tmp/scj/file1_Thu_Jul_23_13:58:24_445022_2015
    result:
        True
##指定原文件名和想要删除的序列号,序列号可以根据时间来定