diff --git a/actions/snapshot b/actions/snapshot index 723014885..146311289 100755 --- a/actions/snapshot +++ b/actions/snapshot @@ -70,9 +70,19 @@ def subcommand_setup(_): command = ['snapper', 'create-config', '/'] subprocess.run(command, check=True) + _set_default_config() _add_fstab_entry('/') +def _set_default_config(): + # Software snapshots' default minimum age: 30 days + command = ['snapper','set-config', 'TIMELINE_CREATE=yes', + 'TIMELINE_LIMIT_HOURLY=10', 'TIMELINE_LIMIT_MONTHLY=2', + 'TIMELINE_LIMIT_WEEKLY=2', 'TIMELINE_LIMIT_YEARLY=0', + 'TIMELINE_LIMIT_DAILY=3', 'NUMBER_MIN_AGE=2592000'] + subprocess.run(command, check=True) + + def _add_fstab_entry(mount_point): """Add mountpoint for subvolumes.""" snapshots_mount_point = os.path.join(mount_point, '.snapshots') diff --git a/plinth/modules/snapshot/__init__.py b/plinth/modules/snapshot/__init__.py index 7447b083c..1a7328a66 100644 --- a/plinth/modules/snapshot/__init__.py +++ b/plinth/modules/snapshot/__init__.py @@ -59,8 +59,14 @@ def setup(helper, old_version=None): helper.call('post', actions.superuser_run, 'snapshot', ['setup']) -def is_timeline_snapshots_enabled(): - """Return whether timeline snapshots are enabled.""" +def get_configuration(): output = actions.superuser_run('snapshot', ['get-config']) output = json.loads(output) - return output['TIMELINE_CREATE'] == 'yes' + return {'enable_timeline_snapshots': output['TIMELINE_CREATE'] == 'yes', + 'hourly_limit': output['TIMELINE_LIMIT_HOURLY'], + 'daily_limit': output['TIMELINE_LIMIT_DAILY'], + 'weekly_limit': output['TIMELINE_LIMIT_WEEKLY'], + 'yearly_limit': output['TIMELINE_LIMIT_YEARLY'], + 'monthly_limit': output['TIMELINE_LIMIT_MONTHLY'], + 'number_min_age': round(int(output['NUMBER_MIN_AGE']) / 86400), + 'timeline_min_age': round(int(output['TIMELINE_MIN_AGE']) / 86400)} diff --git a/plinth/modules/snapshot/forms.py b/plinth/modules/snapshot/forms.py index 60d7a31e0..366592de1 100644 --- a/plinth/modules/snapshot/forms.py +++ b/plinth/modules/snapshot/forms.py @@ -27,3 +27,9 @@ class SnapshotForm(forms.Form): label=_('Enable Timeline Snapshots'), required=False, help_text=_( 'Uncheck this to disable timeline snapshots ' '(hourly, daily, monthly and yearly).')) + hourly_limit = forms.IntegerField(label=_('Hourly Snapshots Limit'),required=False, min_value=0) + daily_limit = forms.IntegerField(label=_('Daily Snapshots Limit'),required=False, min_value=0) + weekly_limit = forms.IntegerField(label=_('Weekly Snapshots Limit'),required=False, min_value=0) + monthly_limit = forms.IntegerField(label=_('Monthly Snapshots Limit'),required=False, min_value=0) + yearly_limit = forms.IntegerField(label=_('Yearly Snapshots Limit'),required=False, min_value=0) + number_min_age = forms.IntegerField(label=_('Software Snapshots Minimum Age (days)'), required=False, min_value=0) diff --git a/plinth/modules/snapshot/templates/snapshot.html b/plinth/modules/snapshot/templates/snapshot.html index aa3222f81..c57b8e169 100644 --- a/plinth/modules/snapshot/templates/snapshot.html +++ b/plinth/modules/snapshot/templates/snapshot.html @@ -23,20 +23,19 @@ {% block configuration %}
-