2024-10-07 Fred Gleason <fredg@paravelsystems.com>

* Added an rdautoback.py(8) utility.

Signed-off-by: Fred Gleason <fredg@paravelsystems.com>
This commit is contained in:
Fred Gleason 2024-10-07 18:13:08 -04:00
parent 33e9e5554b
commit b7920c704b
5 changed files with 119 additions and 0 deletions

View File

@ -24896,3 +24896,5 @@
* Fixed a regression in rdairplay(1) that broke segue transitions.
2024-08-30 Fred Gleason <fredg@paravelsystems.com>
* Incremented the package version to 4.3.0int5.
2024-10-07 Fred Gleason <fredg@paravelsystems.com>
* Added an rdautoback.py(8) utility.

View File

@ -687,6 +687,7 @@ AC_CONFIG_FILES([rivendell.spec \
tests/Makefile \
utils/Makefile \
utils/rdalsaconfig/Makefile \
utils/rdautoback/Makefile \
utils/rdcheckcuts/Makefile \
utils/rdcleandirs/Makefile \
utils/rdclilogedit/Makefile \

View File

@ -24,6 +24,7 @@ if ALSA_RD_AM
ALSACONFIG_RD_OPT = rdalsaconfig
endif
SUBDIRS = $(ALSACONFIG_RD_OPT)\
rdautoback\
rdcheckcuts\
rdcleandirs\
rdclilogedit\

View File

@ -0,0 +1,38 @@
## Makefile.am
##
## utils/rdautoback Makefile.am for Rivendell
##
## (C) Copyright 2024 Fred Gleason <fredg@paravelsystems.com>
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License version 2 as
## published by the Free Software Foundation.
##
## This program 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 along with this program; if not, write to the Free Software
## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
##
##
## Use automake to process this into a Makefile.in
install-exec-local:
mkdir -p $(DESTDIR)/usr/sbin
cp rdautoback.py $(DESTDIR)/usr/sbin/rdautoback.py
../../helpers/install_python.sh rdautoback.py $(DESTDIR)/usr/sbin/rdautoback.py
uninstall-local:
rm -f $(DESTDIR)/usr/sbin/rdautoback.py
bin_SCRIPTS = rdautoback.py
EXTRA_DIST = rdautoback.py
CLEANFILES = *~
MAINTAINERCLEANFILES = *~\
Makefile.in

77
utils/rdautoback/rdautoback.py Executable file
View File

@ -0,0 +1,77 @@
#!%PYTHON_BANGPATH%
# rdautoback.py
#
# Unattended backup script for Rivendell
#
# (C) Copyright 2024 Fred Gleason <fredg@paravelsystems.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program 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 along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
import configparser
import os
from pathlib import Path
import sys
import syslog
USAGE='rdbackup.py <backup-mountpoint>'
if(len(sys.argv)!=2):
print(USAGE)
exit(1)
mountpoint=sys.argv[1]
#
# Load rd.conf(5)
#
rd_config=configparser.ConfigParser(interpolation=None)
rd_config.read_file(open('/etc/rd.conf'))
#
# Open the syslog
#
syslog.openlog('rdautoback.py',logoption=syslog.LOG_PID|syslog.LOG_PERROR,facility=int(rd_config.get('Identity','SyslogFacility',fallback=syslog.LOG_USER)))
syslog.syslog(syslog.LOG_INFO,'Starting Rivendell backup to "'+mountpoint+'"')
#
# Mount backup device
#
Path(mountpoint).mkdir(parents=True,exist_ok=True)
result=os.system(command='mount '+mountpoint)
if(os.waitstatus_to_exitcode(result)!=0):
syslog.syslog(syslog.LOG_ERR,'unable to mount backup drive')
exit(1)
os.system(command='sleep 5')
#
# Dump database
#
cmd='mysqldump -h '+rd_config.get('mySQL','Hostname')+' -u '+rd_config.get('mySQL','Loginname')+' -p'+rd_config.get('mySQL','Password')+' '+rd_config.get('mySQL','Database')+' | gzip > '+mountpoint+'/db.sql.gz'
os.system(command=cmd)
#
# Copy Audio Store
#
cmd='rsync -av --delete /var/snd '+mountpoint
os.system(command=cmd)
#
# Unmount backup device
#
os.system(command='umount '+mountpoint)
os.rmdir(mountpoint)
syslog.syslog(syslog.LOG_INFO,'Completed Rivendell backup to "'+mountpoint+'"')