63 lines
1.5 KiB
Bash
63 lines
1.5 KiB
Bash
|
#!/bin/bash
|
||
|
|
||
|
now=$(date +"%s")
|
||
|
backup_dir="/backup/$now"
|
||
|
|
||
|
# functions
|
||
|
|
||
|
log() {
|
||
|
echo "[$(date)] $*"
|
||
|
}
|
||
|
|
||
|
backup_pg_db() {
|
||
|
sudo -iu postgres pg_dump -Fc "$1" > "${backup_dir}/${1}.dump"
|
||
|
}
|
||
|
|
||
|
backup_dir() {
|
||
|
tar cpf "${backup_dir}/${1}.tar" "$2"
|
||
|
}
|
||
|
# main
|
||
|
|
||
|
if [ $UID != "0" ]; then
|
||
|
echo "You must run it as root."
|
||
|
exit 1
|
||
|
fi
|
||
|
|
||
|
echo -n "Start backup? (y/n) "
|
||
|
read choice
|
||
|
if [ $choice == y ]; then
|
||
|
mkdir -p "${backup_dir}"
|
||
|
log "Starting backup."
|
||
|
|
||
|
|
||
|
log "Backing up /opt..."
|
||
|
backup_dir opt /opt
|
||
|
log "/opt is backed up, starting to backup nextcloud..."
|
||
|
backup_dir nextcloud /var/www/nextcloud
|
||
|
log "Nextcloud is backed up, starting to backup game servers..."
|
||
|
backup_dir servers /home/servers
|
||
|
log "Servers are backed up, starting to backup mailbox."
|
||
|
backup_dir mail /var/mail
|
||
|
log "Mail are backed up, starting to backup peertube"
|
||
|
backup_dir peertube /var/www/peertube
|
||
|
log "Peertube are backed up, starting to backup DBs..."
|
||
|
|
||
|
log "Backing up synapse DB"
|
||
|
backup_pg_db synapse
|
||
|
log "Synapse DB is backed up, backing up nextcloud DB..."
|
||
|
backup_pg_db nextclouddb
|
||
|
log "Nextcloud DB is backed up, backing up pleroma DB..."
|
||
|
backup_pg_db pleroma
|
||
|
log "Pleroma DB is backed up, backing up peerube DB..."
|
||
|
backup_pg_db peertube_prod
|
||
|
log "Peertube DB is backed up, compiling all to one and sending to pomoika..."
|
||
|
tar cvf "${backup_dir}.tar" "${backup_dir}"
|
||
|
log "Done! Now you can restore it!"
|
||
|
else
|
||
|
log "Cancelled."
|
||
|
fi
|
||
|
|
||
|
### to restore
|
||
|
#
|
||
|
#pg_restore -d postgres --clean --create "file backup"
|