2024-11-05 Fred Gleason <fredg@paravelsystems.com>

* Added a rdautocheck(8) utility.

Signed-off-by: Fred Gleason <fredg@paravelsystems.com>
This commit is contained in:
Fred Gleason
2024-11-05 16:41:26 -05:00
parent 823f058d7b
commit 4f6f869c21
7 changed files with 231 additions and 0 deletions

View File

@@ -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
#

View File

@@ -0,0 +1,37 @@
## Makefile.am
##
## utils/rdautocheck 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
../../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

View File

@@ -0,0 +1,69 @@
#!%PYTHON_BANGPATH%
# rdautocheck.py
#
# Read metadata for Rivendell backup sets.
#
# (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 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 <backup-mountpoint1> [<backup-mountpoint2>] [...]'
if(len(sys.argv)<2):
print(USAGE)
exit(1)
for arg in range(1,len(sys.argv)):
PrintMetadata(sys.argv[arg])