Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optionally force overwrite existing backup file #19

Merged
merged 1 commit into from
Nov 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions config.yaml-example
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ gitlab:
#
# When you are using this in your private gitlab instance, you can set it to 0
wait_between_exports: 303
# Maximum Retries
# Number of times to retry, if the export fails
max_tries_number: 12

#
# Backup configuration
Expand Down
26 changes: 17 additions & 9 deletions gitlab-project-export.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
# Parsing arguments
parser = argparse.ArgumentParser(
description="""
GitLab Project Export is
small project using Gitlab API for exporting whole gitlab
GitLab Project Export is a
small project using GitLab API for exporting whole gitlab
project with wikis, issues etc.
Good for migration or simple backup your gitlab projects.
Good for migration or simple backup of your gitlab projects.
""",
epilog='Created by Robert Vojcik <robert@vojcik.net>')

Expand All @@ -36,6 +36,10 @@
'-d', dest='debug', default=False, action='store_const',
const=True, help='Debug mode'
)
parser.add_argument(
'-f', dest='force', default=False, action='store_const',
const=True, help='Force mode - overwrite backup file if exists'
)

args = parser.parse_args()

Expand Down Expand Up @@ -113,9 +117,13 @@
print(" Destination file %s" % (dest_file))

if os.path.isfile(dest_file):
print("File %s already exists" % (dest_file), file=sys.stderr)
return_code += 1
continue
if not args.force:
print("File %s already exists" % (dest_file), file=sys.stderr)
return_code += 1
continue
else:
print("File %s already exists - will be overwritten" % (dest_file))
os.remove(dest_file)

status = gitlab.project_export(project, max_tries_number)

Expand Down Expand Up @@ -154,11 +162,11 @@
# Export for project unsuccessful
print("Export failed for project %s" % (project), file=sys.stderr)
return_code += 1

# If set, wait between exports
if args.debug:
print("Waiting between exports for %d seconds" % (wait_between_exports))
if project != export_projects[-1]:
if args.debug:
print("Waiting between exports for %d seconds" % (wait_between_exports))
time.sleep(wait_between_exports)

sys.exit(return_code)