backup_restore.rst 8.63 KB
Newer Older
1 2
.. _backup:

3 4 5 6
******
Backup
******

7 8 9
Periodic backup
===============

10
A backup of the database and the data are launched every day with a logrotate task.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
It is run at 06:25 a.m. and backups are kept for 7 days.

Logrotate task:

    :file:`/etc/logrotate.d/xivo-backup`

Logrotate cron:

    :file:`/etc/cron.daily/logrotate`


Retrieve the backup
===================

You can retrieve the backup from the web-interface in
:menuselection:`Services --> IPBX --> IPBX Configuration --> Backup Files` page.

28
Otherwise, with shell access, you can retrieve them in :file:`/var/backups/xivo`.
29
In this directory you will find :file:`db.tgz` and :file:`data.tgz` files for the database and data
30
backups.
31

32
Backup scripts:
33 34 35 36 37

    :file:`/usr/sbin/xivo-backup`

Backup location:

38
    :file:`/var/backups/xivo`
39 40


41
What is actually backed-up?
42 43 44
===========================

Data
Etienne Lessard's avatar
Etienne Lessard committed
45
----
46

47
Here is the list of folders and files that are backed-up:
48

49
* :file:`/etc/asterisk/`
sduthil's avatar
sduthil committed
50
* :file:`/etc/consul/`
51
* :file:`/etc/crontab`
52
* :file:`/etc/dahdi/`
53 54 55
* :file:`/etc/dhcp/` 鈿狅笍锔 This will overwrite the network configuration when the backup is restored 鈿
* :file:`/etc/hostname` 鈿狅笍锔 This will overwrite the network configuration when the backup is restored 鈿
* :file:`/etc/hosts` 鈿狅笍锔 This will overwrite the network configuration when the backup is restored 鈿
56
* :file:`/etc/ldap/`
57
* :file:`/etc/network/if-up.d/xivo-routes`
58
* :file:`/etc/network/interfaces`  鈿狅笍锔 This includes the host IP address / netmask and will overwrite the network configuration when the backup is restored 鈿 锔
59
* :file:`/etc/ntp.conf`
60
* :file:`/etc/profile.d/xivo_uuid.sh`
61
* :file:`/etc/resolv.conf` 鈿狅笍锔 This will overwrite the network configuration when the backup is restored 鈿
62
* :file:`/etc/ssl/`
63
* :file:`/etc/systemd/`
64
* :file:`/etc/wanpipe/`
65 66 67 68 69 70 71 72 73
* :file:`/etc/xivo-agentd/`
* :file:`/etc/xivo-agid/`
* :file:`/etc/xivo-amid/`
* :file:`/etc/xivo-auth/`
* :file:`/etc/xivo-call-logd/`
* :file:`/etc/xivo-confd/`
* :file:`/etc/xivo-confgend-client/`
* :file:`/etc/xivo-ctid/`
* :file:`/etc/xivo-dird/`
74
* :file:`/etc/xivo-dird-phoned/`
75 76
* :file:`/etc/xivo-dxtora/`
* :file:`/etc/xivo-purge-db/`
77
* :file:`/etc/xivo/`
78
* :file:`/etc/xivo-xuc.conf`
79
* :file:`/usr/local/bin/`
80 81
* :file:`/usr/local/sbin/`
* :file:`/usr/share/xivo/XIVO-VERSION`
82
* :file:`/var/lib/asterisk/`
83
* :file:`/var/lib/consul/`
84
* :file:`/var/lib/xivo-provd/`
85
* :file:`/var/lib/xivo/`
86 87
* :file:`/var/log/asterisk/`
* :file:`/var/spool/asterisk/`
88
* :file:`/var/spool/cron/crontabs/`
89 90 91 92 93

The following files/folders are excluded from this backup:

* folders:

94 95 96 97
  * :file:`/var/lib/consul/checks`
  * :file:`/var/lib/consul/raft`
  * :file:`/var/lib/consul/serf`
  * :file:`/var/lib/consul/services`
98
  * :file:`/var/lib/xivo-provd/plugins/*/var/cache/*`
99 100
  * :file:`/var/spool/asterisk/monitor/`
  * :file:`/var/spool/asterisk/meetme/`
101

102 103 104 105
* files

  * :file:`/var/lib/xivo-provd/plugins/xivo-polycom*/var/tftpboot/*.ld`

106 107
* log files, coredump files
* audio recordings
108 109
* and, files greater than 10 MiB or folders containing more than 100 files if they belong to one of
  these folders:
110

111 112 113 114 115
  * :file:`/var/lib/xivo/sounds/`
  * :file:`/var/lib/asterisk/sounds/custom/`
  * :file:`/var/lib/asterisk/moh/`
  * :file:`/var/spool/asterisk/voicemail/`
  * :file:`/var/spool/asterisk/monitor/`
116 117 118


Database
Etienne Lessard's avatar
Etienne Lessard committed
119
--------
120

121 122
The database ``asterisk`` from PostgreSQL is backed up. This include almost everything that is
configured via the web interface.
123

124

125 126
.. _manual_backup:

127 128
Creating backup files manually
==============================
129

130 131
.. warning::

132
    A backup file may take a lot of space on the disk.
133
    You should check the free space on the partition before creating one.
134

135 136 137 138 139 140 141 142 143 144 145 146 147 148 149

Database
--------

You can manually create a *database* backup file named :file:`db-manual.tgz` in :file:`/var/tmp` by
issuing the following commands::

   xivo-backup db /var/tmp/db-manual


Files
-----

You can manually create a *data* backup file named :file:`data-manual.tgz` in :file:`/var/tmp` by
issuing the following commands::
150 151

   xivo-backup data /var/tmp/data-manual
152 153


Etienne Lessard's avatar
Etienne Lessard committed
154 155
.. _restore:

156 157 158 159
*******
Restore
*******

Jean-Yves LEBLEU's avatar
Jean-Yves LEBLEU committed
160 161
Introduction
============
162

163
A backup of both the configuration files and the database used by a XiVO installation is done
164
automatically every day.
165
These backups are created in the :file:`/var/backups/xivo` directory and are kept for 7 days.
166

167 168 169 170 171 172
锔忥笍锔忊殸锔 Important Warning 鈿狅笍锔
=====================

A XiVO backup includes the entirety of the original machine's network configuration : it WILL overwrite any present network settings when you restore it.
Remember to change those settings back if required before restarting network services or the machine itself, especially if you do not have physical or console access!

173 174 175
Limitations
===========

176 177
* You must restore a backup on the **same version** of XiVO that was backed up (though the
  architecture -- ``i386`` or ``amd64`` -- may differ)
178
* You must restore a backup on a machine with the **same hostname and IP address**
179
* Be aware that this procedure applies **only to XiVO >= 14.08**
180 181
* XiVO CC configuration files are not backed up. Follow :ref:`Manual XiVO PBX configuration <xivo_pbx_configuration>`
  to restore them.
182

183

184 185
Before Restoring the System
===========================
186

187 188 189
.. warning::

    Before restoring a XiVO on a fresh install you have to setup XiVO using the wizard (see :ref:`configuration_wizard` section).
190

191
Stop monit and all the xivo services::
192

193
   xivo-service stop
194

Etienne Lessard's avatar
Etienne Lessard committed
195

196 197 198
Before restoring the database, all other services connected to it (XiVO CC, MDS) must be stopped also. You can list active connections:
``sudo -u postgres psql -c "SELECT * FROM pg_stat_activity WHERE pid <> pg_backend_pid()"``

Vojtech Sodoma's avatar
Vojtech Sodoma committed
199
If you want to restore XiVO < 2017.06 that was configured for XiVO CC, you must create PostgreSQL user `stats` before
200 201 202
restoring the database. See :ref:`Creating user stats <creating_user_stats>`.


203 204 205
Restoring System Files
======================

206
System files are stored in the data.tgz file located in the :file:`/var/backups/xivo` directory.
207

sduthil's avatar
sduthil committed
208 209
This file contains for example, voicemail files, musics, voice guides, phone sets firmwares,
provisioning server configuration database.
210

Etienne Lessard's avatar
Etienne Lessard committed
211
To restore the file ::
212

213
   tar xvfp /var/backups/xivo/data.tgz -C /
214

Etienne Lessard's avatar
Etienne Lessard committed
215

216 217
Restoring the Database
======================
218

219 220
.. warning::

221
    * This will destroy all the current data in your database.
222 223
    * You have to check the free space on your system partition before extracting the backups.

224 225
Database backups are created as :file:`db.tgz` files in the :file:`/var/backups/xivo` directory.
These tarballs contains a dump of the database used in XiVO.
226

227
In this example, we'll restore the database from a backup file named :file:`db.tgz`
228 229
placed in the home directory of root.

230
First, extract the content of the :file:`db.tgz` file into the :file:`/var/tmp` directory and go inside
231
the newly created directory::
232

233 234
   tar xvf db.tgz -C /var/tmp
   cd /var/tmp/pg-backup
235

Etienne Lessard's avatar
Etienne Lessard committed
236
Drop the asterisk database and restore it with the one from the backup::
237 238

   sudo -u postgres dropdb asterisk
239
   sudo -u postgres pg_restore -C -d postgres asterisk-*.dump
240

241 242
To finalize the restore, see :ref:`after_restore`.

Etienne Lessard's avatar
Etienne Lessard committed
243

244 245 246 247 248 249 250
Troubleshooting
---------------

When restoring the database, if you encounter problems related to the system locale, see
:ref:`postgresql_localization_errors`.


251 252
Alternative: Restoring and Keeping System Configuration
=======================================================
253

254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271
System configuration like network interfaces is stored in the database. It is
possible to keep this configuration and only restore xivo data.

Rename the asterisk database to asterisk_previous::

   sudo -u postgres psql -c 'ALTER DATABASE asterisk RENAME TO asterisk_previous'

Restore the asterisk database from the backup::

   sudo -u postgres pg_restore -C -d postgres asterisk-*.dump

Restore the system configuration tables from the asterisk_previous database::

   sudo -u postgres pg_dump -c -t dhcp -t netiface -t resolvconf asterisk_previous | sudo -u postgres psql asterisk

Drop the asterisk_previous database::

   sudo -u postgres dropdb asterisk_previous
272

273 274 275
.. warning:: Restoring the data.tgz file also restores system files such as host
   hostname, network interfaces, etc. You will need to reapply the network
   configuration if you restore the data.tgz file.
276

277

278 279
.. _after_restore:

280 281
After Restoring The System
==========================
282

sduthil's avatar
sduthil committed
283 284 285 286
Resynchronize the xivo-auth keys::

   xivo-update-keys

287 288 289 290 291 292
Update systemd runtime configuration::

   source /etc/profile.d/xivo_uuid.sh
   systemctl set-environment XIVO_UUID=$XIVO_UUID
   systemctl daemon-reload

293
Restart the services you stopped in the first step::
294

295
   xivo-service start
296

297
You may also reboot the system. Remember that the network settings were overwritten by the backed up settings, check and fix if necessary before rebooting!