Overview
You may have files in binary storage, for which the parent/owning document doesn't appear to exist. This may have happened due to a known issue on Jive 9.0.2.1. This article provides you instructions on how to get a safe-to-delete list of these orphan files and then provides instructions on how to delete them.
Prerequisites
Applies to On-Premises customers only. The customer needs to be able to access the server backend via the Linux terminal and execute commands as the superuser.
Solution
The below bash script will check your binary store for stale/orphan attachments and generate a second script that you can execute to safely delete those files.
1. Execute the below script as root:
#!/bin/bash
## Getting the binstore path, you can set this one manually, (without the jiveSBS folder part, it's hardcoded in the lines below
# export JIVEBINSTOREPATH="/usr/local/jive/jiveBinStore"
export JIVEBINSTOREPATH=$(su - postgres -c "psql core -qtAXc \"SELECT propvalue FROM jiveproperty WHERE name='jive.storageprovider.FileStorageProvider.rootDirectory';\"")
## DB files list
# explanation of the string: export reversed attachment ids, sort the result, pick 3 first digits of the sorted output and generate the full path to files and export all that to /tmp/jv_attachments_db.txt
# 54tnemhcatta is a reverse of attachment45 where 45 is the encoding for dash (-) character
su - postgres -c "psql core -qtAXc \"SELECT REVERSE(attachmentid::varchar) FROM jiveattachment;\"" | sort | perl -lpe's|(\d)(\d)(\d).*|$ENV{JIVEBINSTOREPATH}/jiveSBS/$1/$2/$3/$&54tnemhcatta.bin\n$ENV{JIVEBINSTOREPATH}/jiveSBS/$1/$2/$3/$&54tnemhcatta.key|g' > /tmp/jv_attachments_db.txt
## Filesystem files list
# searching for all the attachments within the binary store and exporting that to /tmp/jv_attachments_file.txt
find $JIVEBINSTOREPATH -regex ".*54tnemhcatta\.bin\|.*54tnemhcatta\.key" | sort > /tmp/jv_attachments_file.txt
## diff and create a script
# adding a shell script header, join is the diff tool that takes the local files list and removes all the lines that are found in the DB file list, then generating strings of rm -f of the lines left and saving the result to /tmp/jv_attachments_rm_diff.txt
echo '#/bin/bash' > /tmp/jv_attachments_rm_diff.txt; join -v1 -v2 /tmp/jv_attachments_file.txt /tmp/jv_attachments_db.txt | perl -lpe's|^.*$|rm -f $&|g' >> /tmp/jv_attachments_rm_diff.txt
# to review the resulting content of the file:
cat /tmp/jv_attachments_rm_diff.txt
Note that these examples use peer authentication, you might want to change that to another form of psql authorization.
The text file in the final output will have a list of commands to delete the orphan files. See the below screenshot for an example:
2. Ensure that you have made a backup of your bin store in a separate directory or disk, before executing the delete (rm) commands.
3. Take the above produced "/tmp/jv_attachments_rm_diff.txt" file and rename it to "/tmp/jv_attachments_rm_diff.sh"
mv /tmp/jv_attachments_rm_diff.txt /tmp/jv_attachments_rm_diff.sh
4. Change its permissions to make it executable
chmod u+x /tmp/jv_attachments_rm_diff.sh
5. Run the above script to delete the files
$ /tmp/jv_attachments_rm_diff.sh
Testing
The stale files should be removed from the disk. Ensure that Jive is working fine before you delete the backup that you took above.
Comments
0 comments
Please sign in to leave a comment.