snapshot: Fix snapshots filling up the disk

- Snapper's cleanup algorithms don't apply limits unless they are specified in
the form of ranges. Changed all limit values in the configuration to ranges.
- Also, all MIN_AGE values have been set to 0 to avoid the disk space filling up
in case of a large number of snapshots generated in a very short amount of time.
- FREE_LIMIT has been increased to 30% from the default 20% since backup
archives also take up disk space on the root partition.

Fixes #1435

Signed-off-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
Joseph Nuthalapati authored and Sunil Mohan Adapa committed 2019-01-08 13:57:46 -08:00
1 parent 8dbf73d3f5
commit 8ba0bda869
3 files changed
+86 -29

No files matched your search

+16 -10
View File
@@ -28,7 +28,7 @@ from plinth.menu import main_menu
from .manifest import backup
version = 3
version = 4
managed_packages = ['snapper']
@@ -67,13 +67,16 @@ def init():
def setup(helper, old_version=None):
"""Install and configure the module."""
helper.install(managed_packages)
helper.call('post', actions.superuser_run, 'snapshot', ['setup'])
if old_version:
helper.call('post', actions.superuser_run, 'snapshot', ['migrate'])
else:
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)
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')
@@ -96,21 +99,24 @@ def get_configuration():
def get_boolean_choice(status):
return ('yes', 'Enabled') if status else ('no', 'Disabled')
def get_max_from_range(key):
return output[key].split('-')[-1]
return {
'enable_timeline_snapshots':
get_boolean_choice(output['TIMELINE_CREATE'] == 'yes'),
'enable_software_snapshots':
get_boolean_choice(is_apt_snapshots_enabled(aug)),
'hourly_limit':
output['TIMELINE_LIMIT_HOURLY'],
get_max_from_range('TIMELINE_LIMIT_HOURLY'),
'daily_limit':
output['TIMELINE_LIMIT_DAILY'],
get_max_from_range('TIMELINE_LIMIT_DAILY'),
'weekly_limit':
output['TIMELINE_LIMIT_WEEKLY'],
'yearly_limit':
output['TIMELINE_LIMIT_YEARLY'],
get_max_from_range('TIMELINE_LIMIT_WEEKLY'),
'monthly_limit':
output['TIMELINE_LIMIT_MONTHLY'],
get_max_from_range('TIMELINE_LIMIT_MONTHLY'),
'yearly_limit':
get_max_from_range('TIMELINE_LIMIT_YEARLY'),
'number_min_age':
round(int(output['NUMBER_MIN_AGE']) / 86400),
}
+16 -13
View File
@@ -98,25 +98,28 @@ def update_configuration(request, old_status, new_status):
def make_config(args):
key, stamp = args[0], args[1]
if old_status[key] != new_status[key]:
return stamp.format(new_status[key])
if 'limit' in key:
return stamp.format('0-{}'.format(new_status[key]))
else:
return stamp.format(new_status[key])
else:
return None
new_status['number_min_age'] = int(new_status['number_min_age']) * 86400
config = filter(None,
map(make_config, [
('enable_timeline_snapshots', 'TIMELINE_CREATE={}'),
('hourly_limit', 'TIMELINE_LIMIT_HOURLY={}'),
('daily_limit', 'TIMELINE_LIMIT_DAILY={}'),
('weekly_limit', 'TIMELINE_LIMIT_WEEKLY={}'),
('monthly_limit', 'TIMELINE_LIMIT_MONTHLY={}'),
('yearly_limit', 'TIMELINE_LIMIT_YEARLY={}'),
('number_min_age', 'NUMBER_MIN_AGE={}'),
]))
config = filter(
None,
map(make_config, [
('enable_timeline_snapshots', 'TIMELINE_CREATE={}'),
('hourly_limit', 'TIMELINE_LIMIT_HOURLY={}'),
('daily_limit', 'TIMELINE_LIMIT_DAILY={}'),
('weekly_limit', 'TIMELINE_LIMIT_WEEKLY={}'),
('monthly_limit', 'TIMELINE_LIMIT_MONTHLY={}'),
('yearly_limit', 'TIMELINE_LIMIT_YEARLY={}'),
('number_min_age', 'NUMBER_MIN_AGE={}'),
]))
if old_status['enable_software_snapshots'] != new_status[
'enable_software_snapshots']:
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: