You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.1 KiB
46 lines
1.1 KiB
#!/usr/bin/env bash
|
|
|
|
### CONSTANTS
|
|
|
|
SYMPA_CONF=/etc/sympa/sympa/sympa.conf
|
|
SYMPA_DOMAIN=$(grep '^domain' "$SYMPA_CONF" | cut -f2)
|
|
|
|
### FUNCTIONS
|
|
|
|
function create_temp_dir {
|
|
temp_name="$SYMPA_DOMAIN-$(date '+%F')"
|
|
temp_dir="/tmp/$temp_name"
|
|
mkdir "$temp_dir"
|
|
}
|
|
|
|
function export_database {
|
|
db_name=sympa
|
|
db_user=sympa
|
|
db_passwd=$(grep '^db_passwd' /etc/sympa/sympa/sympa.conf | cut -f2)
|
|
PGPASSWORD=$db_passwd pg_dump -h localhost -U "$db_user" "$db_name" | gzip >"$temp_dir/database.psql.gz"
|
|
}
|
|
|
|
function export_files {
|
|
tar -C / -cf "$temp_dir/files.tar" etc/sympa/sympa/sympa.conf
|
|
tar -C / -uf "$temp_dir/files.tar" etc/sympa/data_structure.version
|
|
tar -C / -uf "$temp_dir/files.tar" etc/sympa/auth.conf
|
|
tar -C / -uf "$temp_dir/files.tar" var/lib/sympa
|
|
tar -C / -uf "$temp_dir/files.tar" var/spool/sympa
|
|
gzip "$temp_dir/files.tar"
|
|
}
|
|
|
|
function export {
|
|
create_temp_dir
|
|
export_database
|
|
export_files
|
|
tar -C $temp_dir -cf "$temp_name.sympa" .
|
|
rm "$temp_dir" -rf
|
|
}
|
|
|
|
### MAIN
|
|
|
|
# execute as root or use `sudo`
|
|
[[ $(id -u) != 0 ]] && exec sudo $(dirname "$0")/$(basename "$0")
|
|
|
|
set -Eeu
|
|
export
|