diff --git a/config.yaml-example b/config.yaml-example index 42004d6..9f335c3 100644 --- a/config.yaml-example +++ b/config.yaml-example @@ -10,8 +10,10 @@ gitlab: gitlab_url: "https://gitlab.com" token: "MY_PERSONAL_SECRET_TOKEN" projects: - - rvojcik/example-project + - name: rvojcik/example-project + regularity: [year, month, week, day] - rvojcik/group/* + regularity: [year] # # Backup configuration @@ -24,14 +26,16 @@ backup: destination: "/data/backup" # Backup Name template - # Is it possible to use some placeholders in the name + # It is possible to use some placeholders in the name # {PROJECT_NAME} - Name of the project with full path # Path slashes is replaces with dashes. # Example: # rvojcik/project1 => rvojcik-project1 # # {TIME} - Time of the export - backup_name: "gitlab-com-{PROJECT_NAME}-{TIME}.tar.gz" + # {REGULARITY} - The regularity selected as an + # argument passed to the script. + backup_name: "gitlab-com-{PROJECT_NAME}-{REGULARITY}-{TIME}.tar.gz" # Time format tamplate # Time is construct by python strftime. diff --git a/gitlab-project-export.py b/gitlab-project-export.py index cfd69ff..2f0f516 100755 --- a/gitlab-project-export.py +++ b/gitlab-project-export.py @@ -35,6 +35,10 @@ '-d', dest='debug', default=False, action='store_const', const=True, help='Debug mode' ) + parser.add_argument( + '-r', dest='regularity', default="day", + help='Specify the regularity of this backup. See config.yaml-example' + ) args = parser.parse_args() @@ -59,12 +63,17 @@ print("Unable to get projects for your account", file=sys.stderr) sys.exit(1) + if args.debug: + print("regularity is %s" % args.regularity) + # Check projects against config # Create export_projects array for project_pattern in c.config["gitlab"]["projects"]: for gitlabProject in projects: - if re.match(project_pattern, gitlabProject): - export_projects.append(gitlabProject) + if re.match(project_pattern["name"], gitlabProject): + for regularity_pattern in project_pattern["regularity"]: + if re.match(regularity_pattern, args.regularity): + export_projects.append(gitlabProject) if args.debug: print("Projects to export: " + str(export_projects)) @@ -94,8 +103,9 @@ d = date.today() # File template from config file_tmpl = c.config["backup"]["backup_name"] + file_tmpl_reg = file_tmpl.replace("{REGULARITY}", args.regularity) # Projectname in dest_file - dest_file = destination + "/" + file_tmpl.replace( + dest_file = destination + "/" + file_tmpl_reg.replace( "{PROJECT_NAME}", project.replace("/", "-") )