| Jiri Broulik | 634ea8a | 2017-05-31 17:10:03 +0200 | [diff] [blame] | 1 |  | 
|  | 2 | =================== | 
| OlgaGusarenko | a8a80d3 | 2018-07-31 01:31:34 +0300 | [diff] [blame] | 3 | Usage | 
| Jiri Broulik | 634ea8a | 2017-05-31 17:10:03 +0200 | [diff] [blame] | 4 | =================== | 
|  | 5 |  | 
| OlgaGusarenko | a8a80d3 | 2018-07-31 01:31:34 +0300 | [diff] [blame] | 6 | Xtrabackup allows you to backup and restore databases from full | 
|  | 7 | backups or full backups and its incrementals. | 
| Jiri Broulik | 634ea8a | 2017-05-31 17:10:03 +0200 | [diff] [blame] | 8 |  | 
|  | 9 | Sample pillars | 
|  | 10 | ============== | 
|  | 11 |  | 
| OlgaGusarenko | a8a80d3 | 2018-07-31 01:31:34 +0300 | [diff] [blame] | 12 | Backup client with ssh/rsync remote host: | 
| Jiri Broulik | 634ea8a | 2017-05-31 17:10:03 +0200 | [diff] [blame] | 13 |  | 
|  | 14 | .. code-block:: yaml | 
|  | 15 |  | 
|  | 16 | xtrabackup: | 
|  | 17 | client: | 
|  | 18 | enabled: true | 
|  | 19 | full_backups_to_keep: 3 | 
|  | 20 | hours_before_full: 48 | 
|  | 21 | hours_before_incr: 12 | 
|  | 22 | database: | 
|  | 23 | user: username | 
|  | 24 | password: password | 
|  | 25 | target: | 
|  | 26 | host: cfg01 | 
|  | 27 |  | 
| OlgaGusarenko | a8a80d3 | 2018-07-31 01:31:34 +0300 | [diff] [blame] | 28 | .. note:: The ``full_backups_to_keep`` parameter states how many backup will | 
|  | 29 | be stored locally on xtrabackup client. More options to relocate local | 
|  | 30 | backups can be done using ``salt-formula-backupninja``. | 
| Jiri Broulik | 634ea8a | 2017-05-31 17:10:03 +0200 | [diff] [blame] | 31 |  | 
| Adam Tengler | 5b9dd51 | 2018-09-10 15:06:20 +0000 | [diff] [blame] | 32 | Backup client using DB API instead of socket (still needs to be run on the same server as DB): | 
|  | 33 |  | 
|  | 34 | .. code-block:: yaml | 
|  | 35 |  | 
|  | 36 | xtrabackup: | 
|  | 37 | client: | 
|  | 38 | enabled: true | 
|  | 39 | full_backups_to_keep: 3 | 
|  | 40 | hours_before_full: 48 | 
|  | 41 | hours_before_incr: 12 | 
|  | 42 | database: | 
|  | 43 | user: username | 
|  | 44 | password: password | 
|  | 45 | host: localhost | 
|  | 46 | port: 3306 | 
|  | 47 | target: | 
|  | 48 | host: cfg01 | 
|  | 49 |  | 
|  | 50 | .. note:: DB user ``username`` must have "RELOAD" and "REPLICATION CLIENT" | 
|  | 51 | privileges on all databases. | 
|  | 52 |  | 
| OlgaGusarenko | a8a80d3 | 2018-07-31 01:31:34 +0300 | [diff] [blame] | 53 | Backup client with local backup only: | 
| Jiri Broulik | 634ea8a | 2017-05-31 17:10:03 +0200 | [diff] [blame] | 54 |  | 
|  | 55 | .. code-block:: yaml | 
|  | 56 |  | 
|  | 57 | xtrabackup: | 
|  | 58 | client: | 
|  | 59 | enabled: true | 
|  | 60 | full_backups_to_keep: 3 | 
|  | 61 | hours_before_full: 48 | 
|  | 62 | hours_before_incr: 12 | 
|  | 63 | database: | 
|  | 64 | user: username | 
|  | 65 | password: password | 
|  | 66 |  | 
| OlgaGusarenko | a8a80d3 | 2018-07-31 01:31:34 +0300 | [diff] [blame] | 67 | .. note:: The ``full_backups_to_keep`` parameter states how many backup will | 
|  | 68 | be stored locally on xtrabackup client. | 
| Jiri Broulik | 634ea8a | 2017-05-31 17:10:03 +0200 | [diff] [blame] | 69 |  | 
| Adam Tengler | 5b9dd51 | 2018-09-10 15:06:20 +0000 | [diff] [blame] | 70 | Backup client with ssh/rsync to remote host with compression, IO throttling and non-default | 
| OlgaGusarenko | a8a80d3 | 2018-07-31 01:31:34 +0300 | [diff] [blame] | 71 | backup directory on server: | 
| Jiri Broulik | 634ea8a | 2017-05-31 17:10:03 +0200 | [diff] [blame] | 72 |  | 
|  | 73 | .. code-block:: yaml | 
|  | 74 |  | 
|  | 75 | xtrabackup: | 
|  | 76 | client: | 
|  | 77 | enabled: true | 
|  | 78 | full_backups_to_keep: 3 | 
|  | 79 | hours_before_full: 48 | 
|  | 80 | hours_before_incr: 12 | 
|  | 81 | compression: true | 
|  | 82 | compression_threads: 2 | 
| Adam Tengler | 5b9dd51 | 2018-09-10 15:06:20 +0000 | [diff] [blame] | 83 | throttle: 20 | 
| Jiri Broulik | 634ea8a | 2017-05-31 17:10:03 +0200 | [diff] [blame] | 84 | database: | 
|  | 85 | user: username | 
|  | 86 | password: password | 
|  | 87 | target: | 
|  | 88 | host: cfg01 | 
| Marcin Iwinski | f74b953 | 2017-09-28 16:30:47 +0200 | [diff] [blame] | 89 | server: | 
|  | 90 | enabled: false | 
|  | 91 | backup_dir: /srv/backup | 
| Jiri Broulik | 634ea8a | 2017-05-31 17:10:03 +0200 | [diff] [blame] | 92 |  | 
| OlgaGusarenko | a8a80d3 | 2018-07-31 01:31:34 +0300 | [diff] [blame] | 93 | .. note:: More options to relocate local backups can be done using | 
|  | 94 | ``salt-formula-backupninja``. | 
| Jiri Broulik | 634ea8a | 2017-05-31 17:10:03 +0200 | [diff] [blame] | 95 |  | 
| OlgaGusarenko | a8a80d3 | 2018-07-31 01:31:34 +0300 | [diff] [blame] | 96 | .. note:: If the ``server`` section is ommited, backups will be made to | 
|  | 97 | default location, same on both client and server side. | 
| Marcin Iwinski | f74b953 | 2017-09-28 16:30:47 +0200 | [diff] [blame] | 98 |  | 
| Martin Polreich | f33e186 | 2018-03-02 10:30:35 +0100 | [diff] [blame] | 99 | Backup client at exact times: | 
|  | 100 |  | 
| OlgaGusarenko | a8a80d3 | 2018-07-31 01:31:34 +0300 | [diff] [blame] | 101 | .. code-block:: yaml | 
| Martin Polreich | f33e186 | 2018-03-02 10:30:35 +0100 | [diff] [blame] | 102 |  | 
|  | 103 | xtrabackup: | 
|  | 104 | client: | 
|  | 105 | enabled: true | 
|  | 106 | full_backups_to_keep: 3 | 
|  | 107 | incr_before_full: 3 | 
|  | 108 | backup_dir: /var/backups/mysql/xtrabackup | 
|  | 109 | backup_times: | 
| Martin Polreich | 3694851 | 2018-04-04 10:07:58 +0200 | [diff] [blame] | 110 | day_of_week: 0 | 
| Martin Polreich | f33e186 | 2018-03-02 10:30:35 +0100 | [diff] [blame] | 111 | hour: 4 | 
|  | 112 | minute: 52 | 
|  | 113 | compression: true | 
|  | 114 | compression_threads: 2 | 
|  | 115 | database: | 
|  | 116 | user: user | 
|  | 117 | password: password | 
|  | 118 | target: | 
|  | 119 | host: host01 | 
|  | 120 |  | 
| OlgaGusarenko | a8a80d3 | 2018-07-31 01:31:34 +0300 | [diff] [blame] | 121 | .. note:: Parameters in ``backup_times`` section can be used to set up exact | 
|  | 122 | time the cron job should be executed. In this example, the backup job | 
|  | 123 | would be executed every Sunday at 4:52 AM. If any of the individual | 
|  | 124 | ``backup_times`` parameters is not defined, the defalut ``*`` value will | 
|  | 125 | be used. For example, if minute parameter is ``*``, it will run the backup | 
|  | 126 | every minute, which is ususally not desired. | 
| Martin Polreich | f33e186 | 2018-03-02 10:30:35 +0100 | [diff] [blame] | 127 |  | 
| OlgaGusarenko | a8a80d3 | 2018-07-31 01:31:34 +0300 | [diff] [blame] | 128 | Available parameters include: | 
| Martin Polreich | f33e186 | 2018-03-02 10:30:35 +0100 | [diff] [blame] | 129 |  | 
| OlgaGusarenko | a8a80d3 | 2018-07-31 01:31:34 +0300 | [diff] [blame] | 130 | * ``day_of_week`` | 
|  | 131 | * ``day_of_month`` | 
|  | 132 | * ``month`` | 
|  | 133 | * ``hour`` | 
|  | 134 | * ``minute``. | 
| Martin Polreich | f33e186 | 2018-03-02 10:30:35 +0100 | [diff] [blame] | 135 |  | 
| OlgaGusarenko | a8a80d3 | 2018-07-31 01:31:34 +0300 | [diff] [blame] | 136 | See the crontab reference for further info on how to set these | 
|  | 137 | parameters. | 
|  | 138 |  | 
|  | 139 | .. note:: Please be aware that only ``backup_times`` section OR | 
|  | 140 | ``hours_before_full(incr)`` can be defined. If both are defined. The | 
|  | 141 | ``backup_times`` section will be peferred. | 
|  | 142 |  | 
|  | 143 | .. note:: New parameter ``incr_before_full`` needs to be defined. This | 
|  | 144 | number sets number of incremental backups to be run, before a full backup | 
|  | 145 | is performed. | 
| Martin Polreich | f33e186 | 2018-03-02 10:30:35 +0100 | [diff] [blame] | 146 |  | 
| Marcin Iwinski | f74b953 | 2017-09-28 16:30:47 +0200 | [diff] [blame] | 147 | Backup server rsync and non-default backup directory: | 
| Jiri Broulik | 634ea8a | 2017-05-31 17:10:03 +0200 | [diff] [blame] | 148 |  | 
|  | 149 | .. code-block:: yaml | 
|  | 150 |  | 
|  | 151 | xtrabackup: | 
|  | 152 | server: | 
|  | 153 | enabled: true | 
|  | 154 | hours_before_full: 48 | 
|  | 155 | full_backups_to_keep: 5 | 
|  | 156 | key: | 
|  | 157 | xtrabackup_pub_key: | 
|  | 158 | enabled: true | 
|  | 159 | key: key | 
| Marcin Iwinski | f74b953 | 2017-09-28 16:30:47 +0200 | [diff] [blame] | 160 | backup_dir: /srv/backup | 
| Jiri Broulik | 634ea8a | 2017-05-31 17:10:03 +0200 | [diff] [blame] | 161 |  | 
| OlgaGusarenko | a8a80d3 | 2018-07-31 01:31:34 +0300 | [diff] [blame] | 162 | .. note:: The ``hours_before_full`` parameter should have the same value as | 
|  | 163 | is stated on xtrabackup client | 
| Jiri Broulik | 634ea8a | 2017-05-31 17:10:03 +0200 | [diff] [blame] | 164 |  | 
| OlgaGusarenko | a8a80d3 | 2018-07-31 01:31:34 +0300 | [diff] [blame] | 165 | .. note:: If the ``backup_dir`` argument is ommited backups will be made to | 
|  | 166 | default location, same on both client and server side. | 
| Jiri Broulik | 634ea8a | 2017-05-31 17:10:03 +0200 | [diff] [blame] | 167 |  | 
| OlgaGusarenko | a8a80d3 | 2018-07-31 01:31:34 +0300 | [diff] [blame] | 168 | Backup server without strict client restriction: | 
| Jiri Broulik | e662620 | 2018-02-28 16:22:20 +0100 | [diff] [blame] | 169 |  | 
|  | 170 | .. code-block:: yaml | 
|  | 171 |  | 
|  | 172 | xtrabackup: | 
|  | 173 | server: | 
|  | 174 | restrict_clients: false | 
|  | 175 |  | 
| Martin Polreich | f33e186 | 2018-03-02 10:30:35 +0100 | [diff] [blame] | 176 | Backup server at exact times: | 
|  | 177 |  | 
| OlgaGusarenko | a8a80d3 | 2018-07-31 01:31:34 +0300 | [diff] [blame] | 178 | .. code-block:: yaml | 
| Martin Polreich | f33e186 | 2018-03-02 10:30:35 +0100 | [diff] [blame] | 179 |  | 
|  | 180 | xtrabackup: | 
|  | 181 | server: | 
|  | 182 | enabled: true | 
|  | 183 | full_backups_to_keep: 3 | 
|  | 184 | incr_before_full: 3 | 
|  | 185 | backup_dir: /srv/backup | 
|  | 186 | backup_times: | 
| Martin Polreich | 3694851 | 2018-04-04 10:07:58 +0200 | [diff] [blame] | 187 | day_of_week: 0 | 
| Martin Polreich | f33e186 | 2018-03-02 10:30:35 +0100 | [diff] [blame] | 188 | hour: 4 | 
|  | 189 | minute: 52 | 
|  | 190 | key: | 
|  | 191 | xtrabackup_pub_key: | 
|  | 192 | enabled: true | 
|  | 193 | key: key | 
|  | 194 |  | 
| OlgaGusarenko | a8a80d3 | 2018-07-31 01:31:34 +0300 | [diff] [blame] | 195 | .. note:: Parameters in ``backup_times`` section can be used to set up exact | 
|  | 196 | time the cron job should be executed. In this example, the backup job | 
|  | 197 | would be executed every Sunday at 4:52 AM. If any of the individual | 
|  | 198 | ``backup_times`` parameters is not defined, the defalut ``*`` value will | 
|  | 199 | be used. For example, if minute parameter is ``*``, it will run the backup | 
|  | 200 | every minute, which is ususally not desired. | 
| Martin Polreich | f33e186 | 2018-03-02 10:30:35 +0100 | [diff] [blame] | 201 |  | 
| OlgaGusarenko | a8a80d3 | 2018-07-31 01:31:34 +0300 | [diff] [blame] | 202 | See the crontab reference for further info on how to set these parameters. | 
| Martin Polreich | f33e186 | 2018-03-02 10:30:35 +0100 | [diff] [blame] | 203 |  | 
| OlgaGusarenko | a8a80d3 | 2018-07-31 01:31:34 +0300 | [diff] [blame] | 204 | .. note:: Please be aware that only ``backup_times`` section OR | 
|  | 205 | ``hours_before_full(incr)`` can be defined. If both are defined. The | 
|  | 206 | ``backup_times`` section will be peferred. | 
|  | 207 |  | 
|  | 208 | .. note:: New parameter ``incr_before_full`` needs to be defined. This | 
|  | 209 | number sets number of incremental backups to be run, before a full backup | 
|  | 210 | is performed. | 
| Martin Polreich | f33e186 | 2018-03-02 10:30:35 +0100 | [diff] [blame] | 211 |  | 
| Jiri Broulik | e662620 | 2018-02-28 16:22:20 +0100 | [diff] [blame] | 212 | Client restore from local backups: | 
| Jiri Broulik | 634ea8a | 2017-05-31 17:10:03 +0200 | [diff] [blame] | 213 |  | 
|  | 214 | .. code-block:: yaml | 
|  | 215 |  | 
|  | 216 | xtrabackup: | 
|  | 217 | client: | 
|  | 218 | enabled: true | 
|  | 219 | full_backups_to_keep: 5 | 
|  | 220 | hours_before_full: 48 | 
|  | 221 | hours_before_incr: 12 | 
|  | 222 | restore_full_latest: 1 | 
|  | 223 | restore_from: local | 
|  | 224 | compression: true | 
|  | 225 | compressThreads: 2 | 
|  | 226 | database: | 
|  | 227 | user: username | 
|  | 228 | password: password | 
|  | 229 | target: | 
|  | 230 | host: cfg01 | 
|  | 231 | qpress: | 
|  | 232 | source: tar | 
|  | 233 | name: url | 
|  | 234 |  | 
| OlgaGusarenko | a8a80d3 | 2018-07-31 01:31:34 +0300 | [diff] [blame] | 235 | .. note:: restore_full_latest param with a value of 1 means to restore | 
|  | 236 | db from the last full backup and its increments. 2 would mean to | 
|  | 237 | restore second latest full backup and its increments | 
| Jiri Broulik | 634ea8a | 2017-05-31 17:10:03 +0200 | [diff] [blame] | 238 |  | 
| azvyagintsev | 83c4c64 | 2018-08-20 16:47:51 +0300 | [diff] [blame] | 239 | Client restore from remote backups: | 
| Jiri Broulik | 634ea8a | 2017-05-31 17:10:03 +0200 | [diff] [blame] | 240 |  | 
|  | 241 | .. code-block:: yaml | 
|  | 242 |  | 
|  | 243 | xtrabackup: | 
|  | 244 | client: | 
|  | 245 | enabled: true | 
|  | 246 | full_backups_to_keep: 5 | 
|  | 247 | hours_before_full: 48 | 
|  | 248 | hours_before_incr: 12 | 
|  | 249 | restore_full_latest: 1 | 
|  | 250 | restore_from: remote | 
|  | 251 | compression: true | 
|  | 252 | compressThreads: 2 | 
|  | 253 | database: | 
|  | 254 | user: username | 
|  | 255 | password: password | 
|  | 256 | target: | 
|  | 257 | host: cfg01 | 
|  | 258 | qpress: | 
|  | 259 | source: tar | 
|  | 260 | name: url | 
|  | 261 |  | 
| OlgaGusarenko | a8a80d3 | 2018-07-31 01:31:34 +0300 | [diff] [blame] | 262 | .. note:: The ``restore_full_latest`` parameter with a value of 1 | 
|  | 263 | means to restore db from the last full backup and its increments. | 
|  | 264 | 2 would mean to restore second latest full backup and its increments | 
| Jiri Broulik | 634ea8a | 2017-05-31 17:10:03 +0200 | [diff] [blame] | 265 |  | 
| OlgaGusarenko | a8a80d3 | 2018-07-31 01:31:34 +0300 | [diff] [blame] | 266 | Read more | 
|  | 267 | ========= | 
| Jiri Broulik | 634ea8a | 2017-05-31 17:10:03 +0200 | [diff] [blame] | 268 |  | 
|  | 269 | * https://labs.riseup.net/code/projects/xtrabackup/wiki/Configuration | 
|  | 270 | * http://www.debian-administration.org/articles/351 | 
|  | 271 | * http://duncanlock.net/blog/2013/08/27/comprehensive-linux-backups-with-etckeeper-xtrabackup/ | 
|  | 272 | * https://github.com/riseuplabs/puppet-xtrabackup | 
|  | 273 | * http://www.ushills.co.uk/2008/02/backup-with-xtrabackup.html |