remove last remnants of Paths, now only 1 directory per path AND created a new db-container subdir that takes the latest postgres image and adds a crontab / uses cron to run a bkup_users.sh script that dumps the person, refimg and linkage table so that if we ever blow the DB away, we dont lose the users

This commit is contained in:
2022-09-17 22:40:50 +10:00
parent 19bd4285e1
commit 71ec54807a
7 changed files with 36 additions and 40 deletions

6
TODO
View File

@@ -1,9 +1,5 @@
## GENERAL ## GENERAL
* remove multiple Paths from SettingsIPath, etc. * change the rotation code to use that jpeg util to reduce/remove compression loss?
* put a 'job' in to dump those users out to the filesystem so when we rebuild the padb docker container, we dont have to re-add the users/refimgs, etc.
* should I change the rotation code to use that jpeg util to reduce/remove compression loss?
* should allow context menu from View thumbs (particularly useful on search) to show other files around this one by date (maybe that folder or something?) * should allow context menu from View thumbs (particularly useful on search) to show other files around this one by date (maybe that folder or something?)

View File

@@ -13,5 +13,6 @@ RUN truncate -s0 /tmp/preseed.cfg && \
RUN rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* RUN rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN apt-get update && apt-get -y install cron RUN apt-get update && apt-get -y install cron
COPY crontab /etc/crontab COPY crontab /etc/crontab
COPY bkup_users.sh /tmp/
EXPOSE 5432 EXPOSE 5432
CMD ["sh", "-c", "cron ; /usr/local/bin/docker-entrypoint.sh postgres"] CMD ["sh", "-c", "cron ; /usr/local/bin/docker-entrypoint.sh postgres"]

7
db-container/bkup_users.sh Executable file
View File

@@ -0,0 +1,7 @@
#!/bin/bash
pg_dump -a --user=pa --table=person --table=refimg --table=person_refimg_link > /tmp/new_users.sql
tmp=`diff -q /docker-entrypoint-initdb.d/users.sql /tmp/new_users.sql`
if (( $? !=0 && $(stat -c%s "/tmp/new_users.sql") > 200000 )) ; then
cp -f /tmp/new_users.sql /docker-entrypoint-initdb.d/users.sql
fi

View File

@@ -1 +1 @@
* * * * * root pg_dump -a --user=pa --table=person --table=refimg --table=person_refimg_link > /tmp/new_users.sql * * * * * root /tmp/bkup_users.sh

View File

@@ -371,13 +371,11 @@ def GetEntries( OPT ):
paths = [] paths = []
if OPT.path_type == 'Storage': if OPT.path_type == 'Storage':
paths = SettingsSPath() path = SettingsSPath()
elif OPT.path_type == 'Import': elif OPT.path_type == 'Import':
paths = SettingsIPath() path = SettingsIPath()
elif OPT.path_type == 'Bin': elif OPT.path_type == 'Bin':
paths.append(SettingsRBPath()) path = SettingsRBPath()
num_paths = len(paths)
num_entries=0 num_entries=0
path_cnt=1 path_cnt=1
@@ -388,20 +386,13 @@ def GetEntries( OPT ):
update_last_eid = True update_last_eid = True
else: else:
update_last_eid = False update_last_eid = False
for path in paths: prefix = SymlinkName(OPT.path_type,path,path+'/')
if not os.path.exists(path): if OPT.folders:
continue tmp_ents, tmp_num_ents = GetEntriesInFolderView( OPT, prefix )
prefix = SymlinkName(OPT.path_type,path,path+'/') else:
if OPT.folders: tmp_ents, tmp_num_ents = GetEntriesInFlatView( OPT, prefix )
tmp_ents, tmp_num_ents = GetEntriesInFolderView( OPT, prefix ) entries += tmp_ents
else: num_entries += tmp_num_ents
tmp_ents, tmp_num_ents = GetEntriesInFlatView( OPT, prefix )
entries += tmp_ents
num_entries += tmp_num_ents
# if we have another path, keep adding num_etnries, and last_eid is the last path, not this one, so reset to 0
if update_last_eid and path_cnt < num_paths:
OPT.last_eid=0
path_cnt += 1
if update_last_eid: if update_last_eid:
# find pref... via path_type if we are here # find pref... via path_type if we are here

View File

@@ -2245,7 +2245,10 @@ def ReloadMetadata(job):
match=re.search( '(\d+)_([^_]+)', fname ) match=re.search( '(\d+)_([^_]+)', fname )
face_id=match.group(1) face_id=match.group(1)
person_tag=match.group(2) person_tag=match.group(2)
p = session.query(Person).filter(Person.tag==person_tag).one() p = session.query(Person).filter(Person.tag==person_tag).first()
if not p:
print( f"There is a metadata override on the file system for person: {person_tag} - but they are no longer in the DB - skip" )
continue
face_data=GetFaceInMetadata(fname) face_data=GetFaceInMetadata(fname)
if DEBUG: if DEBUG:
print( f"Found metadata showing Override match for person: {person_tag}" ) print( f"Found metadata showing Override match for person: {person_tag}" )

View File

@@ -146,9 +146,9 @@ def SettingsRBPath():
return return
# path setting is an absolute path, just use it, otherwise prepend base_path first # path setting is an absolute path, just use it, otherwise prepend base_path first
if settings.recycle_bin_path[0] == '/': if settings.recycle_bin_path[0] == '/':
path = settings.recycle_bin_path path=settings.recycle_bin_path
else: else:
path = settings.base_path+settings.recycle_bin_path path=settings.base_path+settings.recycle_bin_path
return path return path
############################################################################## ##############################################################################
@@ -161,12 +161,11 @@ def SettingsSPath():
if settings == None: if settings == None:
print("Cannot create file data with no settings / storage path is missing") print("Cannot create file data with no settings / storage path is missing")
return return
for p in settings.storage_path.split("#"): if settings.storage_path[0] == '/':
if p[0] == '/': path=settings.storage_path
paths.append(p) else:
else: path=settings.base_path+settings.storage_path
paths.append(settings.base_path+p) return path
return paths
############################################################################## ##############################################################################
# SettingsIPath(): return modified array of paths (take each path in # SettingsIPath(): return modified array of paths (take each path in
@@ -178,12 +177,11 @@ def SettingsIPath():
if settings == None: if settings == None:
print ("Cannot create file data with no settings / import path is missing") print ("Cannot create file data with no settings / import path is missing")
return return
for p in settings.import_path.split("#"): if settings.import_path[0] == '/':
if p[0] == '/': path=settings.import_path
paths.append(p) else:
else: path=settings.base_path+settings.import_path
paths.append(settings.base_path+p) return path
return paths
############################################################################## ##############################################################################
# SettingsMPath(): return path to actual metadata path from settings # SettingsMPath(): return path to actual metadata path from settings