eb07ab3613
Add the FUSE dependencies for our hosts backed up with borg, along with a small script to make mounting the backups easier. This is the best way to recover something quickly in what is sure to be a stressful situation. Documentation and testing is updated. Change-Id: I1f409b2df952281deedff2ff8f09e3132a2aff08
91 lines
2.9 KiB
Python
91 lines
2.9 KiB
Python
# Copyright 2019 Red Hat, Inc.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
# not use this file except in compliance with the License. You may obtain
|
|
# a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
# License for the specific language governing permissions and limitations
|
|
# under the License.
|
|
|
|
import os.path
|
|
import pytest
|
|
|
|
testinfra_hosts = ['borg-backup01.region.provider.opendev.org',
|
|
'borg-backup-test01.opendev.org',
|
|
'borg-backup-test02.opendev.org']
|
|
|
|
|
|
def test_borg_installed(host):
|
|
f = host.file('/opt/borg/bin/borg')
|
|
assert f.exists
|
|
|
|
cmd = host.run('/opt/borg/bin/borg --version')
|
|
assert cmd.succeeded
|
|
# NOTE(ianw): deliberately pinned; we want to be careful if we
|
|
# update that the new version is compatible with old repos.
|
|
assert '1.1.14' in cmd.stdout
|
|
|
|
def test_borg_server_users(host):
|
|
hostname = host.backend.get_hostname()
|
|
if hostname.startswith('borg-backup-test'):
|
|
pytest.skip()
|
|
|
|
for username in 'borg-borg-backup-test01', 'borg-borg-backup-test02':
|
|
homedir = os.path.join('/opt/backups/', username)
|
|
borg_repo = os.path.join(homedir, 'backup')
|
|
authorized_keys = os.path.join(homedir, '.ssh', 'authorized_keys')
|
|
|
|
user = host.user(username)
|
|
assert user.exists
|
|
assert user.home == homedir
|
|
|
|
f = host.file(authorized_keys)
|
|
assert f.exists
|
|
assert f.contains("ssh-ed25519")
|
|
|
|
f = host.file(borg_repo)
|
|
assert f.exists
|
|
|
|
def test_borg_backup_host_config(host):
|
|
hostname = host.backend.get_hostname()
|
|
if hostname == 'borg-backup01.region.provider.opendev.org':
|
|
pytest.skip()
|
|
|
|
f = host.file('/usr/local/bin/borg-backup')
|
|
assert f.exists
|
|
|
|
f = host.file('/root/.ssh/id_borg_backup_ed25519')
|
|
assert f.exists
|
|
|
|
f = host.file('/root/.ssh/config')
|
|
assert f.exists
|
|
assert f.contains('Host borg-backup01.region.provider.opendev.org')
|
|
|
|
def test_borg_backup(host):
|
|
hostname = host.backend.get_hostname()
|
|
if hostname == 'borg-backup01.region.provider.opendev.org':
|
|
pytest.skip()
|
|
|
|
cmd = host.run(
|
|
'/usr/local/bin/borg-backup borg-backup01.region.provider.opendev.org 2>> '
|
|
'/var/log/borg-backup-borg-backup01.region.provider.opendev.org.log')
|
|
assert cmd.succeeded
|
|
|
|
cmd = host.run(
|
|
'/usr/local/bin/borg-mount borg-backup01.region.provider.opendev.org')
|
|
assert cmd.succeeded
|
|
|
|
cmd = host.run('ls /opt/backups')
|
|
# this directory should now have a directory
|
|
# borg-backup-test0X-YYYY-MM-DDT...
|
|
assert 'borg-backup-test' in cmd.stdout
|
|
|
|
# unmount it for sanity
|
|
cmd = host.run('umount /opt/backups')
|
|
assert cmd.succeeded
|