-
Notifications
You must be signed in to change notification settings - Fork 0
/
koji-backup
executable file
·49 lines (43 loc) · 1.45 KB
/
koji-backup
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
# koji_backup: Backs up the Koji database.
#
# This script is called by the daily_checks job and uses the Koji package
# directory and backup directory specified in the configuration file:
#
# [koji]
# pkgdir = /usr/koji/packages
# backupdir = /usr/koji/backups
#
# You can also specify another directory by running it by hand in the command
# line.
if [ $# -ne 2 ]; then
echo "Usage: koji-backup <koji-dir> <backup-dir>"
exit 1
fi
# Exit on error
set -e
# Output an error message
function error() {
echo "ERROR: $1"
}
# Check that temp directory is secure
eval dirpath="/var/run/rutgers-repotools-2"
if [ ! -d "$dirpath" ]; then
error "$dirvar path is invalid: \"$dirpath\" is not a directory"
exit 1
elif [ "drwx------" != "$(stat -c %A /var/run/rutgers-repotools-2)" ]; then
error "$dirpath does not have correct (700) permissions"
exit 1
elif [ "koji" != "$(stat -c %U /var/run/rutgers-repotools-2)" ]; then
error "$dirpath is not owned by koji"
exit 1
fi
# Dump Koji DB to local disk
echo "Dumping Koji database to disc..."
sudo -u koji sh -c "pg_dump -C koji -U koji | gzip > /var/run/rutgers-repotools-2/koji_dbdump.sql.gz"
# Sync the backup to our backup location
echo "Syncing to backup location..."
rsync --archive --sparse --delete "$1" "$2/packages"
rsync --archive /var/run/rutgers-repotools-2/koji_dbdump.sql.gz "$2"
sudo -u koji sh -c "rm -f /var/run/rutgers-repotools-2/koji_dbdump.sql"
echo "Backup complete!"