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