Subversion Repositories zfs_utils

Rev

Rev 7 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
13 rodolico 1
# Sample script sync
7 rodolico 2
 
13 rodolico 3
sync is just a quick and dirty script I created to utilize replicate beyond a cron job. There is no reason to use it unless you want to go beyond putting a line (with parameters) in your crontab.
4
 
5
However, it is useful for me, and it does show how to script the replicate script.
6
 
7
## Configuration
8
 
9
The configuration file is named sync.yaml, and it is in the same directory as the script itself. There is a sample you can use.
10
 
11
- **email** - how to send reports
12
 
13
  - **from** - e-mail account which is put in the From: header
14
 
15
  - **notify** - e-mail account put in the To: header
16
 
17
  - **subject** - Subject line of e-mail
18
 
19
- **target** and **source** - parameters for connecting to the target and source
20
 
21
  - **server** - One of them must be remote, but not both. You can put the keyword server, followed by a DNS name or an IP address. Again, **server** only exist in either target or source, but not both.
22
 
23
  - **dataset** - Either a list of what you want to replicate from, or a single entry for where you want to replicate to.
24
 
25
    - **target** - single dataset to replicate to. The actual dataset will be target/child, where child is calculated from the source entries
26
 
27
    - **source** - A list of sources. The key (thing on the left) is a child dataset. The value (thing on the right) is the full parent. So, if you want to replicate from pool/mydata/personal, you wouild put personal on the left, and pool/mydata on the right.
28
 
29
- General - true is anything other than a blank or a 0
30
 
31
  - **recurse** - if set to true, will replicate the datasets and all children of them
32
 
33
  - **filter** - used as a regular expression to filter the snapshots on the source. datasets not matching this filter are not in the initial sync, but if you sync a newer snapshot, it most likely will bring that one over also.
34
 
35
  - **bandwidth** - if this has a value, will limit the bandwidth in *bytes per second* of the transfer. If you want it in bits per second (normal bandwidth unit), divide the bits per second to get the bytes per second. This is performed by placing the Unix command *pv* between the send and receive and using the -L flag. If pv is not installed, this will be ignored.
36
 
37
  - **verbose** - integer between 0 and 2
38
 
39
    - 0 - no report is generated
40
 
41
    - 1 - basic report is generated with name of command, bytes transferred and number of seconds it took to do the replication
42
 
43
    - 2 - full report including all commands used, and all values returned by the verbose flag to either send or receive, whichever is local
44
 
45
  - **dryrun** - passes dryrun flag to replicate. replicate reports what command(s) would be executed, but does not run them.
46
 
47
  - **testing** - if true, does not execute replicate, but shows the command that would be used.
48
 
49
  - **shutdown** - Upon completion of replication, shut down the local server. **Warning**: if you get this wrong, you can end up shutting down a production server (ie, source)
50
 
51
  - **stats**: if set, will save a date/time stamp, the child dataset name (from source), the number of seconds the job took and the number of bytes which were transferred to a file with this name. If the filename contains the '/' character, it is assumed to be a fully qualified path/filename. Otherwise it is assumed to be a file in the same directory as sync
52
 
53
## Requirements
54
 
55
- YAML::Tiny installed.
56
 
57
  - pkg install p5-YAML-Tiny-1.74 or
58
 
59
  - cpan -i YAML::Tiny
60
 
61
- It also requires *pv* if you want bandwith limitations.
62
 
63
  - pkg install pv
64
 
65
- sendmail (or some variant) configured for report e-mails
66
 
67
- sync also assumes the replicate script and configuration file are in the same directory as sync itself
68
 
69
## Program Flow
70
 
71
1. Configuration file loaded, die if not found or corrupt
72
 
73
2. servername loaded from `hostname` command
74
 
75
3. quick e-mail generated telling user that replication has been started
76
 
77
4. Verifies whichever machine is remote is actually up
78
 
79
5. Checks for maintenance flag and exits immediately if it exists. Used for servers which have the shutdown flag set; bypasses that.
80
 
81
6. Parse command line flags. These will override configuration file
82
 
83
7. for each source defined
84
 
85
   1. build replicate command line
86
 
87
   2. save replicate command into status variable
88
 
89
   3. If not testing
90
 
91
      1. execute replicate command line
92
 
93
      2. save output from replicate command to status
94
 
95
      3. updates statistics file, if set (and not testing)
96
 
97
8. if testing
98
 
99
   1. dump status to screen
100
 
101
9. if not testing
102
 
103
   1. send status via e-mail
104
 
105
   2. shut down machine if flag set