mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-05-27 10:44:33 +00:00
snapper: enable/diable apt snapshots
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
8416c0831d
commit
0b3880a4cf
@ -28,6 +28,7 @@ import augeas
|
|||||||
|
|
||||||
FSTAB = '/etc/fstab'
|
FSTAB = '/etc/fstab'
|
||||||
AUG_FSTAB = '/files/etc/fstab'
|
AUG_FSTAB = '/files/etc/fstab'
|
||||||
|
DEFAULT_FILE = '/etc/default/snapper'
|
||||||
|
|
||||||
|
|
||||||
def parse_arguments():
|
def parse_arguments():
|
||||||
@ -54,6 +55,9 @@ def parse_arguments():
|
|||||||
subparser = subparsers.add_parser('rollback', help='Rollback to snapshot')
|
subparser = subparsers.add_parser('rollback', help='Rollback to snapshot')
|
||||||
subparser.add_argument('number', help='Number of snapshot to rollback to')
|
subparser.add_argument('number', help='Number of snapshot to rollback to')
|
||||||
|
|
||||||
|
subparser = subparsers.add_parser('disable-apt-snapshot', help='enable/disable apt snapshots')
|
||||||
|
subparser.add_argument('state')
|
||||||
|
|
||||||
subparsers.required = True
|
subparsers.required = True
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
@ -155,6 +159,20 @@ def _get_default_snapshot():
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
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.set('/augeas/load/Shellvars/lens', 'Shellvars.lns')
|
||||||
|
aug.set('/augeas/load/Shellvars/incl[last() + 1]', DEFAULT_FILE)
|
||||||
|
aug.load()
|
||||||
|
|
||||||
|
aug.set('/files' + DEFAULT_FILE + '/DISABLE_APT_SNAPSHOT', arguments.state)
|
||||||
|
aug.save()
|
||||||
|
|
||||||
|
|
||||||
def subcommand_create(_):
|
def subcommand_create(_):
|
||||||
"""Create snapshot."""
|
"""Create snapshot."""
|
||||||
command = ['snapper', 'create', '--description', 'manually created']
|
command = ['snapper', 'create', '--description', 'manually created']
|
||||||
|
|||||||
@ -18,6 +18,7 @@
|
|||||||
FreedomBox app to manage filesystem snapshots.
|
FreedomBox app to manage filesystem snapshots.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import augeas
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
@ -25,7 +26,7 @@ from django.utils.translation import ugettext_lazy as _
|
|||||||
from plinth import actions
|
from plinth import actions
|
||||||
from plinth.menu import main_menu
|
from plinth.menu import main_menu
|
||||||
|
|
||||||
version = 3
|
version = 4
|
||||||
|
|
||||||
managed_packages = ['snapper']
|
managed_packages = ['snapper']
|
||||||
|
|
||||||
@ -52,6 +53,8 @@ service = None
|
|||||||
|
|
||||||
manual_page = 'Snapshots'
|
manual_page = 'Snapshots'
|
||||||
|
|
||||||
|
DEFAULT_FILE = '/etc/default/snapper'
|
||||||
|
|
||||||
|
|
||||||
def init():
|
def init():
|
||||||
"""Initialize the module."""
|
"""Initialize the module."""
|
||||||
@ -65,7 +68,26 @@ def setup(helper, old_version=None):
|
|||||||
helper.call('post', actions.superuser_run, 'snapshot', ['setup'])
|
helper.call('post', actions.superuser_run, 'snapshot', ['setup'])
|
||||||
|
|
||||||
|
|
||||||
|
def load_augeas():
|
||||||
|
"""Initialize Augeas."""
|
||||||
|
aug = augeas.Augeas(flags=augeas.Augeas.NO_LOAD +
|
||||||
|
augeas.Augeas.NO_MODL_AUTOLOAD)
|
||||||
|
|
||||||
|
# shell-script config file lens
|
||||||
|
aug.set('/augeas/load/Shellvars/lens', 'Shellvars.lns')
|
||||||
|
aug.set('/augeas/load/Shellvars/incl[last() + 1]', DEFAULT_FILE)
|
||||||
|
aug.load()
|
||||||
|
return aug
|
||||||
|
|
||||||
|
|
||||||
|
def is_apt_snapshots_enabled(aug):
|
||||||
|
"""Return whether APT snapshots is enabled."""
|
||||||
|
value = aug.get('/files' + DEFAULT_FILE + '/DISABLE_APT_SNAPSHOT')
|
||||||
|
return value != 'yes'
|
||||||
|
|
||||||
|
|
||||||
def get_configuration():
|
def get_configuration():
|
||||||
|
aug = load_augeas()
|
||||||
output = actions.superuser_run('snapshot', ['get-config'])
|
output = actions.superuser_run('snapshot', ['get-config'])
|
||||||
output = json.loads(output)
|
output = json.loads(output)
|
||||||
|
|
||||||
@ -75,6 +97,8 @@ def get_configuration():
|
|||||||
return {
|
return {
|
||||||
'enable_timeline_snapshots':
|
'enable_timeline_snapshots':
|
||||||
get_boolean_choice(output['TIMELINE_CREATE'] == 'yes'),
|
get_boolean_choice(output['TIMELINE_CREATE'] == 'yes'),
|
||||||
|
'enable_software_snapshots':
|
||||||
|
get_boolean_choice(is_apt_snapshots_enabled(aug)),
|
||||||
'hourly_limit':
|
'hourly_limit':
|
||||||
output['TIMELINE_LIMIT_HOURLY'],
|
output['TIMELINE_LIMIT_HOURLY'],
|
||||||
'daily_limit':
|
'daily_limit':
|
||||||
|
|||||||
@ -29,6 +29,11 @@ class SnapshotForm(forms.Form):
|
|||||||
'(hourly, daily, monthly and yearly).'),
|
'(hourly, daily, monthly and yearly).'),
|
||||||
choices=[('yes', 'Enabled'), ('no', 'Disabled')])
|
choices=[('yes', 'Enabled'), ('no', 'Disabled')])
|
||||||
|
|
||||||
|
enable_software_snapshots = forms.ChoiceField(
|
||||||
|
label=_('Software Snapshots'),
|
||||||
|
help_text=_('Enable or disable software snapshots '),
|
||||||
|
choices=[('yes', 'Enabled'), ('no', 'Disabled')])
|
||||||
|
|
||||||
hourly_limit = forms.IntegerField(
|
hourly_limit = forms.IntegerField(
|
||||||
label=_('Hourly Snapshots Limit'), min_value=0,
|
label=_('Hourly Snapshots Limit'), min_value=0,
|
||||||
help_text=_('Keep a maximum of this many hourly snapshots.'))
|
help_text=_('Keep a maximum of this many hourly snapshots.'))
|
||||||
|
|||||||
@ -108,6 +108,12 @@ def update_configuration(request, old_status, new_status):
|
|||||||
('number_min_age', 'NUMBER_MIN_AGE={}'),
|
('number_min_age', 'NUMBER_MIN_AGE={}'),
|
||||||
]))
|
]))
|
||||||
|
|
||||||
|
if old_status['enable_software_snapshots'] != new_status['enable_software_snapshots']:
|
||||||
|
if new_status['enable_software_snapshots'] == 'yes':
|
||||||
|
actions.superuser_run('snapshot', ['disable-apt-snapshot', 'no'])
|
||||||
|
else:
|
||||||
|
actions.superuser_run('snapshot', ['disable-apt-snapshot', 'yes'])
|
||||||
|
|
||||||
try:
|
try:
|
||||||
actions.superuser_run('snapshot', ['set-config', " ".join(config)])
|
actions.superuser_run('snapshot', ['set-config', " ".join(config)])
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user