From 4f6f869c21a2366f0f6c6b186a732666d23a1bd8 Mon Sep 17 00:00:00 2001 From: Fred Gleason Date: Tue, 5 Nov 2024 16:41:26 -0500 Subject: [PATCH] 2024-11-05 Fred Gleason * Added a rdautocheck(8) utility. Signed-off-by: Fred Gleason --- ChangeLog | 2 + docs/manpages/Makefile.am | 9 ++++ docs/manpages/rdautocheck.xml | 74 ++++++++++++++++++++++++++++++++ rivendell.spec.in | 2 + utils/rdautoback/rdautoback.py | 38 ++++++++++++++++ utils/rdautocheck/Makefile.am | 37 ++++++++++++++++ utils/rdautocheck/rdautocheck.py | 69 +++++++++++++++++++++++++++++ 7 files changed, 231 insertions(+) create mode 100644 docs/manpages/rdautocheck.xml create mode 100644 utils/rdautocheck/Makefile.am create mode 100755 utils/rdautocheck/rdautocheck.py diff --git a/ChangeLog b/ChangeLog index 36addb11..a75c477c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -24930,3 +24930,5 @@ run on Python 3.6. * Fixed a regression in rdautorest(8) that caused it to crash when run on Python 3.6. +2024-11-05 Fred Gleason + * Added a rdautocheck(8) utility. diff --git a/docs/manpages/Makefile.am b/docs/manpages/Makefile.am index aed018c0..07fe2cf1 100644 --- a/docs/manpages/Makefile.am +++ b/docs/manpages/Makefile.am @@ -57,6 +57,9 @@ all-local: rdadmin.1\ rdautoback.8\ rdautoback.html\ rdautoback.pdf\ + rdautocheck.8\ + rdautocheck.html\ + rdautocheck.pdf\ rdautorest.8\ rdautorest.html\ rdautorest.pdf\ @@ -114,6 +117,8 @@ man_MANS = rdadmin.1\ rdalsaconfig.1\ rdautoback.8\ rdautorest.8\ + rdautocheck.8\ + rdautocheck.8\ rdclilogedit.1\ rd.conf.5\ rdconvert.1\ @@ -148,6 +153,10 @@ EXTRA_DIST = exitcodes.xml\ rdautoback.html\ rdautoback.pdf\ rdautoback.xml\ + rdautocheck.8\ + rdautocheck.html\ + rdautocheck.pdf\ + rdautocheck.xml\ rdautorest.8\ rdautorest.html\ rdautorest.pdf\ diff --git a/docs/manpages/rdautocheck.xml b/docs/manpages/rdautocheck.xml new file mode 100644 index 00000000..81e18355 --- /dev/null +++ b/docs/manpages/rdautocheck.xml @@ -0,0 +1,74 @@ + + + + + rdautocheck + 8 + November 2024 + Linux Audio Manual + + + rdautocheck + Display metadata for coherent Rivendell backups + + + + + Fred + Gleason + fredg@paravelsystems.com + + Application Author + + + + + + + rdautocheck + mount-pt1 + mount-pt2 + ... + + + + + Description + + rdautocheck8 is a command-line + tool used for displaying the metadata for one or more coherent backups + (database+audiostore) of the Rivendell Radio Automation System generated + by rdautoback8. + + + rdautocheck8 will attempt + to mount the filesystem corresponding to each mount point specified in + its invocation and, if successful, print the contents of the + INFO.txt file in the mounted filesystem + to standard output, following which the volume will be unmounted. + + + + See Also + + + fstab5 + + , + + rdautoback8 + + , + + rdautorest8 + + + + + + + diff --git a/rivendell.spec.in b/rivendell.spec.in index 93b94271..ed4f76ec 100644 --- a/rivendell.spec.in +++ b/rivendell.spec.in @@ -479,6 +479,7 @@ rm -rf $RPM_BUILD_ROOT %{_mandir}/man8/rdmarkerset.8.gz %{_mandir}/man8/rdservice.8.gz %{_mandir}/man8/rdautoback.8.gz +%{_mandir}/man8/rdautocheck.8.gz %{_mandir}/man8/rdautorest.8.gz @DOC_PATH@/* %{_libdir}/librd-@VERSION@.so @@ -500,6 +501,7 @@ rm -rf $RPM_BUILD_ROOT %{_bindir}/rdsinglestart %{_sbindir}/rddbmgr %{_sbindir}/rdautoback +%{_sbindir}/rdautocheck %{_sbindir}/rdautorest @HPI_FILE1@ @HPI_FILE2@ diff --git a/utils/rdautoback/rdautoback.py b/utils/rdautoback/rdautoback.py index c3f8d60f..408c0840 100755 --- a/utils/rdautoback/rdautoback.py +++ b/utils/rdautoback/rdautoback.py @@ -21,6 +21,8 @@ # import configparser +import datetime +import MySQLdb import os from pathlib import Path import sys @@ -70,6 +72,42 @@ os.system(command=cmd) cmd='rsync -av --delete /var/snd '+mountpoint os.system(command=cmd) +# +# Generate Info File +# +with open(mountpoint+'/INFO.txt','w') as f: + f.write('[Backup]\n') + f.write('Name='+mountpoint+'\n') + with os.popen('date --iso-8601=seconds',mode='r') as f1: + f.write('DateTime='+f1.read()) + f1.close() + try: + db=MySQLdb.connect(user=rd_config.get('mySQL','Loginname'), + passwd=rd_config.get('mySQL','Password'), + host=rd_config.get('mySQL','Hostname'), + database=rd_config.get('mySQL','Database'), + charset='utf8mb4') + except TypeError: + db=MySQLdb.connect(user=rd_config.get('mySQL','Loginname'), + password=rd_config.get('mySQL','Password'), + host=rd_config.get('mySQL','Hostname'), + database=rd_config.get('mySQL','Database'), + charset='utf8mb4') + cursor=db.cursor() + cursor.execute('select `REALM_NAME` from `SYSTEM`') + f.write('RealmName='+cursor.fetchone()[0]+'\n') + cursor.execute('select `DB` from `VERSION`') + f.write('DatabaseSchema='+str(cursor.fetchone()[0])+'\n') + db.close() + with os.popen('du -h '+mountpoint+'/snd',mode='r') as f1: + values=f1.read().split('\t') + f.write('AudioStorage='+values[0]+'\n') + f1.close() + with os.popen('ls -1 '+mountpoint+'/snd | wc -l') as f1: + f.write('AudioFiles='+f1.read()) + f1.close() + f.close() + # # Unmount backup device # diff --git a/utils/rdautocheck/Makefile.am b/utils/rdautocheck/Makefile.am new file mode 100644 index 00000000..e922f0f2 --- /dev/null +++ b/utils/rdautocheck/Makefile.am @@ -0,0 +1,37 @@ +## Makefile.am +## +## utils/rdautocheck 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 + ../../helpers/install_python.sh rdautocheck.py $(DESTDIR)/usr/sbin/rdautocheck + +uninstall-local: + rm -f $(DESTDIR)/usr/sbin/rdautocheck + +noinst_SCRIPTS = rdautocheck.py + +EXTRA_DIST = rdautocheck.py + +CLEANFILES = *~ + +MAINTAINERCLEANFILES = *~\ + Makefile.in diff --git a/utils/rdautocheck/rdautocheck.py b/utils/rdautocheck/rdautocheck.py new file mode 100755 index 00000000..be62b17c --- /dev/null +++ b/utils/rdautocheck/rdautocheck.py @@ -0,0 +1,69 @@ +#!%PYTHON_BANGPATH% + +# rdautocheck.py +# +# Read metadata for Rivendell backup sets. +# +# (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 datetime +import MySQLdb +import os +from pathlib import Path +import sys +import syslog + +def PrintMetadata(mntpt): + # + # Mount backup device + # + Path(mntpt).mkdir(parents=True,exist_ok=True) + result=os.WEXITSTATUS(os.system(command='mount '+mntpt+" 2> /dev/null")) + if((result!=0)and(result!=64)): + print(mntpt+': [not found]') + print() + return + os.system(command='sleep 5') + + # + # Read Info File + # + try: + with open(mntpt+'/INFO.txt','r') as f: + print(mntpt+':') + print(f.read()) + f.close() + except FileNotFoundError: + print(mntpt+':') + print('[no metadata found]') + print() + + # + # Unmount backup device + # + os.system(command='umount '+mntpt) + os.rmdir(mntpt) + +USAGE='rdautocheck.py [] [...]' + +if(len(sys.argv)<2): + print(USAGE) + exit(1) +for arg in range(1,len(sys.argv)): + PrintMetadata(sys.argv[arg]) +