Univention Bugzilla – Attachment 8291 Details for
Bug 38554
Limit number of backups in /var/univention-backup
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
/usr/share/ucs-test/10_ldap/101_test_univention_ldap_backup_limit
101_test_univention_ldap_backup_limit (text/plain), 2.44 KB, created by
Julius Hinrichs
on 2016-12-07 13:15:56 CET
(
hide
)
Description:
/usr/share/ucs-test/10_ldap/101_test_univention_ldap_backup_limit
Filename:
MIME Type:
Creator:
Julius Hinrichs
Created:
2016-12-07 13:15:56 CET
Size:
2.44 KB
patch
obsolete
>#!/usr/share/ucs-test/runner python >## desc: Test if the number of LDAP backups is limited correctly >## roles: [domaincontroller_master] >## tags: [basic, apptest] >## bugs: [38554] >## packages: [univention-ldap-server] >## exposure: dangerous > > >import os >import subprocess >import time > >from univention.config_registry import handler_set >from univention.testing.ucr import UCSTestConfigRegistry >from univention.testing.utils import fail > > >BACKUP_SCRIPT = '/usr/sbin/univention-ldap-backup' >BACKUP_LIMIT = 'ucr/univention-ldap-backup/limit' >BACKUP_DIRECTORY = '/var/univention-backup' >BACKUP_PREFIX = 'ldap-backup_' >BACKUP_EXTENSION = '.ldif.gz' >BACKUP_LOG_EXTENSION = '.log.gz' >DATE_FORMAT = '%Y%m%d' >TEST_DATE = '19000101' # long before the epoch > > >def count_backups(): > backups = [backup for backup in os.listdir(BACKUP_DIRECTORY) if backup.endswith(BACKUP_EXTENSION)] > return len(backups) > > ># Move the latest backup (and log) to a temporary directory, to allow new backup. >today = time.strftime(DATE_FORMAT) >backup_today = os.path.join(BACKUP_DIRECTORY, ''.join([BACKUP_PREFIX, today, BACKUP_EXTENSION])) >backup_log_today = os.path.join(BACKUP_DIRECTORY, ''.join([BACKUP_PREFIX, today, BACKUP_LOG_EXTENSION])) >backup_original = os.path.join(BACKUP_DIRECTORY, 'temp', os.path.basename(backup_today)) >backup_log_original = os.path.join(BACKUP_DIRECTORY, 'temp', os.path.basename(backup_log_today)) >if os.path.exists(backup_today): > os.renames(backup_today, backup_original) >if os.path.exists(backup_log_today): > os.renames(backup_log_today, backup_log_original) > ># This file should be automatically deleted when the limit is exceeded. >test_backup = os.path.join(BACKUP_DIRECTORY, ''.join([BACKUP_PREFIX, TEST_DATE, BACKUP_EXTENSION])) >open(test_backup, 'a').close() > >backups_before = count_backups() > ># Set the limit to the current number of backups and make a new backup. >error = None >with UCSTestConfigRegistry() as ucr: > handler_set(['%s=%d' % (BACKUP_LIMIT, backups_before)]) > try: > subprocess.check_output(BACKUP_SCRIPT) > except subprocess.CalledProcessError as e: > error = e > >backups_after = count_backups() > ># Cleanup >if os.path.exists(backup_original): > os.renames(backup_original, backup_today) >if os.path.exists(backup_log_original): > os.renames(backup_log_original, backup_log_today) > >if error: > fail(error.output) >if os.path.exists(test_backup): > fail('The oldest backup was not deleted.') >if backups_after != backups_before: > fail('The total number of backups changed unexpectedly.')
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 38554
:
7995
|
8291
|
8891
|
9178