mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-04-15 09:51:21 +00:00
snapshot: Enable backup/restore
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
316d765629
commit
03a6cf25e5
@ -22,9 +22,11 @@ Configuration helper for filesystem snapshots.
|
||||
import argparse
|
||||
import json
|
||||
import os
|
||||
import signal
|
||||
import subprocess
|
||||
|
||||
import augeas
|
||||
import dbus
|
||||
|
||||
FSTAB = '/etc/fstab'
|
||||
AUG_FSTAB = '/files/etc/fstab'
|
||||
@ -51,6 +53,8 @@ def parse_arguments():
|
||||
subparser = subparsers.add_parser('set-config',
|
||||
help='Configure automatic snapshots')
|
||||
subparser.add_argument('config')
|
||||
subparsers.add_parser('kill-daemon',
|
||||
help='Kill snapperd to reload configuration')
|
||||
|
||||
subparser = subparsers.add_parser('rollback', help='Rollback to snapshot')
|
||||
subparser.add_argument('number', help='Number of snapshot to rollback to')
|
||||
@ -94,8 +98,8 @@ def _add_fstab_entry(mount_point):
|
||||
"""Add mountpoint for subvolumes."""
|
||||
snapshots_mount_point = os.path.join(mount_point, '.snapshots')
|
||||
|
||||
aug = augeas.Augeas(
|
||||
flags=augeas.Augeas.NO_LOAD + augeas.Augeas.NO_MODL_AUTOLOAD)
|
||||
aug = augeas.Augeas(flags=augeas.Augeas.NO_LOAD +
|
||||
augeas.Augeas.NO_MODL_AUTOLOAD)
|
||||
aug.set('/augeas/load/Fstab/lens', 'Fstab.lns')
|
||||
aug.set('/augeas/load/Fstab/incl[last() + 1]', FSTAB)
|
||||
aug.load()
|
||||
@ -163,8 +167,8 @@ def _get_default_snapshot():
|
||||
def subcommand_disable_apt_snapshot(arguments):
|
||||
"""Set flag to Enable/Disable apt software snapshots in config files"""
|
||||
# Initialize Augeas
|
||||
aug = augeas.Augeas(
|
||||
flags=augeas.Augeas.NO_LOAD + augeas.Augeas.NO_MODL_AUTOLOAD)
|
||||
aug = augeas.Augeas(flags=augeas.Augeas.NO_LOAD +
|
||||
augeas.Augeas.NO_MODL_AUTOLOAD)
|
||||
aug.set('/augeas/load/Shellvars/lens', 'Shellvars.lns')
|
||||
aug.set('/augeas/load/Shellvars/incl[last() + 1]', DEFAULT_FILE)
|
||||
aug.load()
|
||||
@ -230,6 +234,29 @@ def subcommand_get_config(_):
|
||||
print(json.dumps(config))
|
||||
|
||||
|
||||
def subcommand_kill_daemon(_):
|
||||
"""Kill the snapper daemon.
|
||||
|
||||
This is generally not necessary because we do configuration changes via
|
||||
snapperd. However, when the configuration is restored from a backup. We
|
||||
need to kill the daemon to reload configuration.
|
||||
|
||||
Ideally, we should be able to reload/terminate the service using systemd.
|
||||
|
||||
"""
|
||||
bus = dbus.SystemBus()
|
||||
|
||||
dbus_object = bus.get_object('org.freedesktop.DBus', '/')
|
||||
dbus_interface = dbus.Interface(dbus_object,
|
||||
dbus_interface='org.freedesktop.DBus')
|
||||
try:
|
||||
pid = dbus_interface.GetConnectionUnixProcessID('org.opensuse.Snapper')
|
||||
except dbus.exceptions.DBusException:
|
||||
pass
|
||||
else:
|
||||
os.kill(pid, signal.SIGTERM)
|
||||
|
||||
|
||||
def subcommand_rollback(arguments):
|
||||
"""Rollback to snapshot."""
|
||||
command = [
|
||||
|
||||
@ -15,7 +15,7 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
@system @snapshots
|
||||
@system @snapshot @backups
|
||||
Feature: Storage Snapshots
|
||||
Run storage snapshots application - Snapper.
|
||||
|
||||
@ -32,3 +32,11 @@ Scenario: Configure snapshots
|
||||
Given snapshots are configured with timeline snapshots disabled, software snapshots disabled, hourly limit 10, daily limit 3, weekly limit 2, monthly limit 2, yearly limit 0, delete old software snapshots 15
|
||||
When I configure snapshots with timeline snapshots enabled, software snapshots enabled, hourly limit 3, daily limit 2, weekly limit 1, monthly limit 1, yearly limit 1, delete old software snapshots 2
|
||||
Then snapshots should be configured with timeline snapshots enabled, software snapshots enabled, hourly limit 3, daily limit 2, weekly limit 1, monthly limit 1, yearly limit 1, delete old software snapshots 2
|
||||
|
||||
Scenario: Backup and restore snapshot
|
||||
When I configure snapshots with timeline snapshots disabled, software snapshots disabled, hourly limit 10, daily limit 3, weekly limit 2, monthly limit 2, yearly limit 0, delete old software snapshots 15
|
||||
And I create a backup of the snapshot app data
|
||||
And I configure snapshots with timeline snapshots enabled, software snapshots enabled, hourly limit 3, daily limit 2, weekly limit 1, monthly limit 1, yearly limit 1, delete old software snapshots 2
|
||||
And I export the snapshot app data backup
|
||||
And I restore the snapshot app data backup
|
||||
Then snapshots should be configured with timeline snapshots disabled, software snapshots disabled, hourly limit 10, daily limit 3, weekly limit 2, monthly limit 2, yearly limit 0, delete old software snapshots 15
|
||||
|
||||
@ -26,6 +26,8 @@ from django.utils.translation import ugettext_lazy as _
|
||||
from plinth import actions
|
||||
from plinth.menu import main_menu
|
||||
|
||||
from .manifest import backup
|
||||
|
||||
version = 3
|
||||
|
||||
managed_packages = ['snapper']
|
||||
@ -112,3 +114,8 @@ def get_configuration():
|
||||
'number_min_age':
|
||||
round(int(output['NUMBER_MIN_AGE']) / 86400),
|
||||
}
|
||||
|
||||
|
||||
def restore_post(packet):
|
||||
"""Run after restore."""
|
||||
actions.superuser_run('snapshot', ['kill-daemon'])
|
||||
|
||||
27
plinth/modules/snapshot/manifest.py
Normal file
27
plinth/modules/snapshot/manifest.py
Normal file
@ -0,0 +1,27 @@
|
||||
#
|
||||
# This file is part of FreedomBox.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
"""
|
||||
Application manifest for snapshot.
|
||||
"""
|
||||
|
||||
from plinth.modules.backups.api import validate as validate_backup
|
||||
|
||||
backup = validate_backup({
|
||||
'config': {
|
||||
'files': ['/etc/snapper/configs/root', '/etc/default/snapper']
|
||||
}
|
||||
})
|
||||
Loading…
x
Reference in New Issue
Block a user