diff --git a/ChangeLog b/ChangeLog index 40afeb45..825fd15c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -24896,3 +24896,5 @@ * Fixed a regression in rdairplay(1) that broke segue transitions. 2024-08-30 Fred Gleason * Incremented the package version to 4.3.0int5. +2024-10-07 Fred Gleason + * Added an rdautoback.py(8) utility. diff --git a/configure.ac b/configure.ac index 5baf1ee5..3062cef9 100644 --- a/configure.ac +++ b/configure.ac @@ -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 \ diff --git a/utils/Makefile.am b/utils/Makefile.am index 38e5675e..2f631682 100644 --- a/utils/Makefile.am +++ b/utils/Makefile.am @@ -24,6 +24,7 @@ if ALSA_RD_AM ALSACONFIG_RD_OPT = rdalsaconfig endif SUBDIRS = $(ALSACONFIG_RD_OPT)\ + rdautoback\ rdcheckcuts\ rdcleandirs\ rdclilogedit\ diff --git a/utils/rdautoback/Makefile.am b/utils/rdautoback/Makefile.am new file mode 100644 index 00000000..e2d9d231 --- /dev/null +++ b/utils/rdautoback/Makefile.am @@ -0,0 +1,38 @@ +## Makefile.am +## +## utils/rdautoback Makefile.am for Rivendell +## +## (C) Copyright 2024 Fred Gleason +## +## 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 diff --git a/utils/rdautoback/rdautoback.py b/utils/rdautoback/rdautoback.py new file mode 100755 index 00000000..59456708 --- /dev/null +++ b/utils/rdautoback/rdautoback.py @@ -0,0 +1,77 @@ +#!%PYTHON_BANGPATH% + +# rdautoback.py +# +# Unattended backup script for Rivendell +# +# (C) Copyright 2024 Fred Gleason +# +# 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 ' + +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+'"')