forked from xapi-project/xen-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
host-backup
executable file
·33 lines (26 loc) · 1.4 KB
/
host-backup
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/bash
#
# Copyright (c) Citrix Systems 2008. All rights reserved.
#
# Experimental backup script
# NB if this script returns non-zero then the host-backup CLI command will fail.
# Create a backup of the pool-database. This is needed because the state in memory
# is not guarranteed to be flushed to disk.
DATE=$(date +%F--%k-%M-%S)
POOL_DB_BACKUP=/var/backup/pool-database-${DATE}
[ -e ${POOL_DB_BACKUP} ] && rm -f ${POOL_DB_BACKUP}
mkdir -p $(dirname ${POOL_DB_BACKUP})
xe pool-dump-database file-name=${POOL_DB_BACKUP}
# Exclude everything under /tmp (as it is temporary) and everything under /var/crash
# (as it might contain large sparse files). The directories themselves still need to
# exist, however, for xapi to function correctly.
tar --exclude 'tmp/*' --exclude 'tmp/.*' --exclude 'var/crash/*' --exclude 'var/crash/.*' \
--exclude 'var/log/audit*' \
--exclude 'var/xsconfig/*' --exclude 'var/xsconfig/.*' \
--exclude 'var/xapi/[0-9a-f]*-[0-9a-f]*-[0-9a-f]*-[0-9a-f]*-[0-9a-f]*' \
--sparse --preserve-permissions --to-stdout --gzip --one-file-system -C / -c .
# Remove the backup of the pool-database. We only need it to be present in the tar file.
# During restore the tar file is extracted over the backup partition which is then made
# bootable. Following a reboot the user must manually call "xe pool-restore-database" on
# the pool-database backup file.
rm -f ${POOL_DB_BACKUP}