backup_server: Move bitbucket backup to own role
This commit is contained in:
parent
0d72e9e920
commit
1520f8dabf
2 changed files with 1 additions and 79 deletions
|
@ -1,51 +0,0 @@
|
||||||
#!/usr/bin/env python3
|
|
||||||
|
|
||||||
import os
|
|
||||||
import json
|
|
||||||
from subprocess import call
|
|
||||||
from urllib.request import urlopen
|
|
||||||
|
|
||||||
USERS = ["tmakinen"]
|
|
||||||
BACKUPDIR = "/srv/backup/bitbucket.org"
|
|
||||||
|
|
||||||
|
|
||||||
def repolist(username):
|
|
||||||
f = urlopen(f"https://api.bitbucket.org/2.0/repositories/{username}")
|
|
||||||
data = json.load(f)
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
for repo in data["values"]:
|
|
||||||
yield (
|
|
||||||
{
|
|
||||||
"name": repo["name"],
|
|
||||||
"scm": repo["scm"],
|
|
||||||
"wiki": repo["has_wiki"],
|
|
||||||
"issues": repo["has_issues"],
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def gitbackup(destination, repo):
|
|
||||||
if not os.path.exists(destination):
|
|
||||||
os.makedirs(destination)
|
|
||||||
call(["git", "clone", "--quiet", repo, destination])
|
|
||||||
else:
|
|
||||||
os.chdir(destination)
|
|
||||||
call(["git", f"--git-dir={destination}/.git", "pull", "--quiet"])
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
for user in USERS:
|
|
||||||
for repo in repolist(user):
|
|
||||||
if repo["scm"] == "git":
|
|
||||||
gitbackup(
|
|
||||||
f"{BACKUPDIR}/{user}/{repo['name']}",
|
|
||||||
f"https://bitbucket.org/{user}/{repo['name']}.git",
|
|
||||||
)
|
|
||||||
if repo["wiki"]:
|
|
||||||
gitbackup(
|
|
||||||
f"{BACKUPDIR}/{user}/{repo['name']}-wiki",
|
|
||||||
f"https://bitbucket.org/{user}/{repo['name']}.git/wiki",
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
raise NotImplementedError("{repo['scm']} repositories not supported")
|
|
|
@ -1,11 +1,8 @@
|
||||||
---
|
---
|
||||||
- name: Install packages
|
- name: Install packages
|
||||||
ansible.builtin.package:
|
ansible.builtin.package:
|
||||||
name: "{{ item }}"
|
name: rclone
|
||||||
state: installed
|
state: installed
|
||||||
with_items:
|
|
||||||
- git
|
|
||||||
- rclone
|
|
||||||
|
|
||||||
- name: Create backup group
|
- name: Create backup group
|
||||||
ansible.builtin.group:
|
ansible.builtin.group:
|
||||||
|
@ -38,27 +35,3 @@
|
||||||
owner: root
|
owner: root
|
||||||
group: "{{ ansible_wheel }}"
|
group: "{{ ansible_wheel }}"
|
||||||
follow: false
|
follow: false
|
||||||
|
|
||||||
- name: Create Bitbucket backup directory
|
|
||||||
ansible.builtin.file:
|
|
||||||
path: /export/backup/bitbucket.org
|
|
||||||
state: directory
|
|
||||||
mode: "0775"
|
|
||||||
owner: root
|
|
||||||
group: backup
|
|
||||||
|
|
||||||
- name: Install Bitbucket backup script
|
|
||||||
ansible.builtin.copy:
|
|
||||||
dest: /usr/local/sbin/backup-bitbucket
|
|
||||||
src: backup-bitbucket.py
|
|
||||||
mode: "0755"
|
|
||||||
owner: root
|
|
||||||
group: "{{ ansible_wheel }}"
|
|
||||||
|
|
||||||
- name: Add Bitbucket backup cron job
|
|
||||||
ansible.builtin.cron:
|
|
||||||
name: bitbucket-backup
|
|
||||||
job: /usr/local/sbin/backup-bitbucket
|
|
||||||
hour: "03"
|
|
||||||
minute: "10"
|
|
||||||
user: backup
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue