Debian Codegraph @

ansible_collections/lowlydba/sqlserver/plugins/modules/backup.py

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # (c) 2022, John McCall (@lowlydba)
5 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
6
7 DOCUMENTATION = r'''
8 ---
9 module: backup
10 short_description: Performs a backup operation
11 description:
12 - Performs any type of database backup operation.
13 version_added: 0.8.0
14 options:
15 database:
16 description:
17 - The database to process.
18 type: str
19 required: true
20 path:
21 description:
22 - Path in which to place the backup files.
23 - If not specified, the backups will be placed in the default backup location for SqlInstance.
24 type: str
25 required: false
26 file_path:
27 description:
28 - The name of the file to backup to.
29 - If no name is specified then the backup files will be named C(DatabaseName_yyyyMMddHHmm) (i.e. C(Database1_201714022131))
30 type: str
31 required: false
32 increment_prefix:
33 description:
34 - If set, this will prefix backup files with an incrementing integer (ie; C(1-), C(2-)).
35 - Using this has been alleged to improved restore times on some Azure based SQL Database platforms.
36 type: bool
37 required: false
38 default: false
39 replace_in_name:
40 description:
41 - If set, the following list of strings will be replaced in the FilePath and Path strings.
42 C(instancename) - will be replaced with the instance Name
43 C(servername) - will be replaced with the server name
44 C(dbname) - will be replaced with the database name
45 C(timestamp) - will be replaced with the timestamp (either the default, or the format provided)
46 C(backuptype) - will be replaced with C(Full), C(Log), or C(Differential) as appropriate
47 type: bool
48 required: false
49 default: false
50 copy_only:
51 description:
52 - The backup will be CopyOnly.
53 type: bool
54 required: false
55 default: false
56 type:
57 description:
58 - The type of backup to perform.
59 type: str
60 required: false
61 default: 'database'
62 choices: ['full', 'log', 'differential', 'diff', 'database']
63 create_folder:
64 description:
65 - If set, database is backed up to its own subfolder within the path.
66 type: bool
67 required: false
68 default: false
69 file_count:
70 description:
71 - The number of striped files to create the backup with.
72 type: int
73 required: false
74 default: 0
75 compress:
76 description:
77 - If set, use compression when creating the backup if it is supported by the version and edition.
78 type: bool
79 required: false
80 default: false
81 checksum:
82 description:
83 - If set, the backup checksum will be calculated.
84 type: bool
85 required: false
86 default: false
87 verify:
88 description:
89 - If set, the backup will be verified via C(RESTORE VERIFYONLY)
90 type: bool
91 required: false
92 default: false
93 max_transfer_size:
94 description:
95 - Sets the size of the unit of transfer. Values must be a multiple of 64kb.
96 type: int
97 required: false
98 default: 0
99 block_size:
100 description:
101 - Specifies block size to use.
102 type: str
103 required: false
104 choices: ['0.5kb','1kb','2kb','4kb','8kb','16kb','32kb','64kb']
105 buffer_count:
106 description:
107 - Number of I/O buffers to use.
108 type: int
109 required: false
110 default: 0
111 azure_base_url:
112 description:
113 - The URL to the base container of an Azure Storage account to write backups to.
114 type: str
115 required: false
116 azure_credential:
117 description:
118 - The name of the credential on the SQL instance that can write to the I(azure_base_url),
119 only needed if using Storage access keys If using SAS credentials, the command will look for a credential with a name matching the I(azure_base_url).
120 type: str
121 required: false
122 no_recovery:
123 description:
124 - If set, performs a tail log backup.
125 type: bool
126 required: false
127 default: false
128 build_path:
129 description:
130 - By default this command will not attempt to create missing paths, this switch will change the behaviour so that it will.
131 type: bool
132 required: false
133 default: false
134 with_format:
135 description:
136 - Formats the media as the first step of the backup operation.
137 type: bool
138 required: false
139 default: false
140 initialize:
141 description:
142 - Initializes the media as part of the backup operation.
143 type: bool
144 required: false
145 default: false
146 timestamp_format:
147 description:
148 - By default the command timestamps backups using the format C(yyyyMMddHHmm). Using this option this can be overridden.
149 type: str
150 required: false
151 ignore_file_checks:
152 description:
153 - If set, stops the function from checking path validity.
154 type: bool
155 required: false
156 default: false
157 encryption_algorithm:
158 description:
159 - Specifies the Encryption Algorithm to used.
160 type: str
161 required: false
162 choices: ['AES128','AES192','AES256','TRIPLEDES']
163 encryption_certificate:
164 description:
165 - The name of the certificate to be used to encrypt the backups.
166 type: str
167 required: false
168 author: "John McCall (@lowlydba)"
169 requirements:
170 - L(dbatools,https://www.powershellgallery.com/packages/dbatools/) PowerShell module
171 extends_documentation_fragment:
172 - lowlydba.sqlserver.sql_credentials
173 - lowlydba.sqlserver.attributes.check_mode
174 - lowlydba.sqlserver.attributes.platform_all
175 '''
176
177 EXAMPLES = r'''
178 - name: Create striped full database backup in default dir
179 lowlydba.sqlserver.backup:
180 sql_instance: sql-01.myco.io
181 database: LowlyDB
182 type: full
183 file_count: 8
184
185 - name: Create t-log backup
186 lowlydba.sqlserver.backup:
187 sql_instance: sql-01.myco.io
188 database: LowlyDB
189 type: log
190 '''
191
192 RETURN = r'''
193 data:
194 description: Modified output from the C(Backup-DbaDatabase) function.
195 returned: success, but not in check_mode.
196 type: dict
197 '''