Exemplo n.º 1
0
def backup_user_metadata(username):
    """
    Backup all metadata including email addresses and SSH keys of a single user
    """

    user = gitlab_lib.get_user_metadata(username)
    backup_dir = os.path.join(OUTPUT_BASEDIR, "user_%s_%s" % (user['id'], user['username']))
    if not os.path.exists(backup_dir): os.mkdir(backup_dir)
    
    gitlab_lib.log(u"Backing up metadata of user %s [ID %s]" % (user["username"], user["id"]))
    dump(backup_dir, "user.json", user)
    dump(backup_dir, "projects.json", gitlab_lib.get_projects(username))
    dump(backup_dir, "ssh.json", gitlab_lib.fetch(gitlab_lib.USER_SSHKEYS % (gitlab_lib.API_URL, user["id"])))
    dump(backup_dir, "email.json", gitlab_lib.fetch(gitlab_lib.USER_EMAILS % (gitlab_lib.API_URL, user["id"])))
Exemplo n.º 2
0

#
# MAIN PART
#

if args.dryrun:
    print("Running in simulation mode\n")

gitlab_lib.debug("Setting up work queue")

if args.project:
    queue.put(gitlab_lib.get_project(args.project))
    delete_old_jobs(queue)
else:
    for project in gitlab_lib.get_projects():
        queue.put(project)

    gitlab_lib.debug("Processing work queue")

    for _ in range(args.number):
        processes.append(gitlab_lib.create_process(delete_old_jobs, (queue, )))

    # wait for processes to finish the work
    while queue.qsize() > 0:
        time.sleep(5)

        # check if a process crashed and must be restarted
        if len(processes) < int(
                args.number) and queue.qsize() > len(processes):
            gitlab_lib.debug("Starting new process")
Exemplo n.º 3
0
                gitlab_lib.log(u"Backing up %s from project %s [ID %s]" % (component, project['name'], project['id']))
                dump(backup_dir,
                     component + ".json",
                     gitlab_lib.fetch(api_url % (gitlab_lib.API_URL, project['id'])))

            else:
                gitlab_lib.log("Component %s disabled for project %s [ID %s]" % (component, project['name'], project['id']))


#
# MAIN PART
#

OUTPUT_BASEDIR = args.output or "."
queue = Queue()

if not os.path.exists(OUTPUT_BASEDIR):
    os.mkdir(OUTPUT_BASEDIR)

# Backup metadata of a single user
if args.user:
    backup_user_metadata(args.user)

# Backup all projects or only the projects of a single user
for project in gitlab_lib.get_projects(args.user, personal=True):
    queue.put(project)

# Start processes and let em backup every project
for process in range(int(args.number)):
    gitlab_lib.create_process(backup, (args.repository, queue))
Exemplo n.º 4
0
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# It is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License.
# If not, see <http://www.gnu.org/licenses/>.


import sys
import argparse
import gitlab_lib
import backup_config

parser = argparse.ArgumentParser()
parser.add_argument("-a", "--all", help="Show all not projects not only personal", action="store_true")
parser.add_argument("-s", "--server", help="Gitlab server name", default=backup_config.SERVER)
parser.add_argument("-t", "--token", help="Private token", default=backup_config.TOKEN)
parser.add_argument("-U", "--user", help="Username to backup")
args = parser.parse_args()

if not args.server or not args.token:
    print("You must at least specify --server and --token")
    sys.exit(1)

for project in gitlab_lib.get_projects(args.user, personal=(not args.all)):
    print project['name']
Exemplo n.º 5
0
args = parser.parse_args()

if not args.server or not args.token or not args.project:
    print "You must at least specify --server, --token and --project"
    sys.exit(1)


#
# MAIN PART
#
projects = []

try:
    projects.append(gitlab_lib.fetch(gitlab_lib.PROJECT_METADATA % (int(args.project),)))
except ValueError:
    projects = [x for x in gitlab_lib.get_projects() \
                if args.project in (x['name_with_namespace'] or x['description'])]

if len(projects) == 0:
    print "Found nothing"
else:
    for project in projects:
        if args.details:
            keys = project.keys()
            keys.sort()

            for key in keys:
                print u"%s: %s" % (key, project[key])
                print u"-" * 79

            print "\n"
Exemplo n.º 6
0
# Backup metadata of a single user
if args.user:
    gitlab_lib.backup_user_metadata(args.user)

if not gitlab_lib.core.QUIET: sys.stdout.write("Setting up work queue")

# Backup only projects found by given project id or name
if args.project:
    for project in gitlab_lib.get_project_metadata(args.project):
        if not gitlab_lib.QUIET: sys.stdout.write(".")
        work_queue.put(project)

# Backup all projects or only the projects of a single user
else:
    for project in gitlab_lib.get_projects(args.user, personal=True):
        if not gitlab_lib.core.QUIET: sys.stdout.write(".")
        work_queue.put(project)

if not gitlab_lib.core.QUIET: sys.stdout.write("\n")

if work_queue.qsize() == 0:
    gitlab_lib.error("Cannot find any projects to backup!")
else:
    nr_of_jobs = work_queue.qsize()

    if nr_of_processes > nr_of_jobs:
        nr_of_processes = nr_of_jobs

    # Start processes and let em backup every project
    for process in range(nr_of_processes):