11# rotate-backups: Simple command line interface for backup rotation.
22#
33# Author: Peter Odding <peter@peterodding.com>
4- # Last Change: February 12 , 2020
4+ # Last Change: February 13 , 2020
55# URL: https://github.com/xolox/python-rotate-backups
66
77"""
160160 readable and/or writable for the current user (or the user logged in to a
161161 remote system over SSH).
162162
163+ -S, --syslog=CHOICE
164+
165+ Explicitly enable or disable system logging instead of letting the program
166+ figure out what to do. The values '1', 'yes', 'true' and 'on' enable system
167+ logging whereas the values '0', 'no', 'false' and 'off' disable it.
168+
163169 -f, --force
164170
165171 If a sanity check fails an error is reported and the program aborts. You
194200
195201# External dependencies.
196202import coloredlogs
203+ from coloredlogs import WINDOWS
204+ from coloredlogs .syslog import enable_system_logging
197205from executor import validate_ionice_class
198- from humanfriendly import parse_path , pluralize
206+ from humanfriendly import coerce_boolean , parse_path , pluralize
199207from humanfriendly .terminal import usage
200208from verboselogs import VerboseLogger
201209
213221
214222def main ():
215223 """Command line interface for the ``rotate-backups`` program."""
216- coloredlogs .install (syslog = True )
224+ coloredlogs .install ()
217225 # Command line option defaults.
218226 rotation_scheme = {}
219227 kw = dict (include_list = [], exclude_list = [])
220228 parallel = False
221229 use_sudo = False
230+ use_syslog = (not WINDOWS )
222231 # Internal state.
223232 selected_locations = []
224233 # Parse the command line arguments.
225234 try :
226- options , arguments = getopt .getopt (sys .argv [1 :], 'M:H:d:w:m:y:I:x:jpri:c:r:uC :fnvqh' , [
235+ options , arguments = getopt .getopt (sys .argv [1 :], 'M:H:d:w:m:y:I:x:jpri:c:C:uS :fnvqh' , [
227236 'minutely=' , 'hourly=' , 'daily=' , 'weekly=' , 'monthly=' , 'yearly=' ,
228237 'include=' , 'exclude=' , 'parallel' , 'prefer-recent' , 'relaxed' ,
229- 'ionice=' , 'config=' , 'removal-command=' , 'use-sudo' , 'force ' ,
230- 'dry-run' , 'verbose' , 'quiet' , 'help' ,
238+ 'ionice=' , 'config=' , 'removal-command=' , 'use-sudo' , 'syslog= ' ,
239+ 'force' , ' dry-run' , 'verbose' , 'quiet' , 'help' ,
231240 ])
232241 for option , value in options :
233242 if option in ('-M' , '--minutely' ):
@@ -263,6 +272,8 @@ def main():
263272 kw ['removal_command' ] = removal_command
264273 elif option in ('-u' , '--use-sudo' ):
265274 use_sudo = True
275+ elif option in ('-S' , '--syslog' ):
276+ use_syslog = coerce_boolean (value )
266277 elif option in ('-f' , '--force' ):
267278 kw ['force' ] = True
268279 elif option in ('-n' , '--dry-run' ):
@@ -277,6 +288,8 @@ def main():
277288 return
278289 else :
279290 assert False , "Unhandled option! (programming error)"
291+ if use_syslog :
292+ enable_system_logging ()
280293 if rotation_scheme :
281294 logger .verbose ("Rotation scheme defined on command line: %s" , rotation_scheme )
282295 if arguments :
0 commit comments