feat: Detect MariaDB vs MySQL automatically
This commit is contained in:
parent
a23f37dbd4
commit
078dd7f335
3 changed files with 35 additions and 13 deletions
|
@ -4,9 +4,21 @@ limit=1000
|
|||
folder=/var/www/friendica
|
||||
user=friendica
|
||||
phpversion=php8.2
|
||||
dbengine=mariadb
|
||||
dbengine=""
|
||||
if [[ -n $(type mariadb) ]]; then
|
||||
dbengine="mariadb"
|
||||
elif [[ -n $(type mysql) ]]; then
|
||||
dbengine="mysql"
|
||||
else
|
||||
exit
|
||||
fi
|
||||
db=friendica
|
||||
dboptimizer=mariadb-optimize
|
||||
dboptimizer=""
|
||||
if [[ -n $(type mariadb-optimize) ]]; then
|
||||
dboptimizer="mariadb-optimize"
|
||||
elif [[ -n $(type mysqloptimize) ]]; then
|
||||
dbengine="mysqloptimize"
|
||||
fi
|
||||
intense_optimizations=${1:-"0"}
|
||||
|
||||
bash -c "cd ${folder} && sudo -u ${user} ${phpversion} bin/console.php maintenance 1 \"Database maintenance\"" #&> /dev/null
|
||||
|
|
|
@ -1,4 +1,13 @@
|
|||
#!/bin/bash
|
||||
#Check for mariadb vs. mysql
|
||||
dbengine=""
|
||||
if [[ -n $(type mariadb) ]]; then
|
||||
dbengine="mariadb"
|
||||
elif [[ -n $(type mysql) ]]; then
|
||||
dbengine="mysql"
|
||||
else
|
||||
exit
|
||||
fi
|
||||
db="friendica"
|
||||
url=friendica.example.net
|
||||
avatarfolder=/var/www/friendica/avatar
|
||||
|
@ -23,21 +32,14 @@ loop() {
|
|||
"${dbengine}" "${db}" -N -B -q -e "delete from \`post-thread-user\` where \`author-id\` = ${lineb} or \`causer-id\` = ${lineb} or \`owner-id\` = ${lineb}"
|
||||
"${dbengine}" "${db}" -N -B -q -e "delete from \`post-user\` where \`author-id\` = ${lineb} or \`causer-id\` = ${lineb} or \`owner-id\` = ${lineb}"
|
||||
"${dbengine}" "${db}" -N -B -q -e "delete from \`post-tag\` where cid = ${lineb}"
|
||||
"${dbengine}" "${db}" -N -B -q -e "create temporary table tmp_post (select \`uri-id\` from \`post\` where \`owner-id\` = ${lineb} or \`author-id\` = ${lineb} or \`causer-id\` = ${lineb}); delete p.* from \`post-content\` p inner join \`tmp_post\` t where p.\`uri-id\` = t.\`uri-id\`;"
|
||||
"${dbengine}" "${db}" -N -B -q -e "delete from \`post\` where \`owner-id\` = ${lineb} or \`author-id\` = ${lineb} or \`causer-id\` = ${lineb}"
|
||||
"${dbengine}" "${db}" -N -B -q -e "delete from \`post-content\` where \`uri-id\` = ${lineb}"
|
||||
"${dbengine}" "${db}" -N -B -q -e "delete from \`photo\` where \`contact-id\` = ${lineb}"
|
||||
"${dbengine}" "${db}" -N -B -q -e "delete from \`contact\` where \`id\` = ${lineb}"
|
||||
"${dbengine}" "${db}" -N -B -q -e "delete from \`apcontact\` where \`uri-id\` = ${lineb}"
|
||||
"${dbengine}" "${db}" -N -B -q -e "delete from \`diaspora-contact\` where \`uri-id\` = ${lineb}"
|
||||
}
|
||||
|
||||
#Check for mariadb vs. mysql
|
||||
dbengine=""
|
||||
if [[ -n $(type mariadb) ]]; then
|
||||
dbengine="mariadb"
|
||||
elif [[ -n $(type mysql) ]]; then
|
||||
dbengine="mysql"
|
||||
fi
|
||||
#Check if our dependencies are installed
|
||||
if [[ -n $(type curl) && -n "${dbengine}" && -n $(type "${dbengine}") && -n $(type date) ]]; then
|
||||
date
|
||||
|
|
|
@ -1,6 +1,14 @@
|
|||
#!/bin/bash
|
||||
IFS="
|
||||
"
|
||||
dbengine=""
|
||||
if [[ -n $(type mariadb) ]]; then
|
||||
dbengine="mariadb"
|
||||
elif [[ -n $(type mysql) ]]; then
|
||||
dbengine="mysql"
|
||||
else
|
||||
exit
|
||||
fi
|
||||
#Set your parameters here
|
||||
url=friendica.example.net
|
||||
db=friendica
|
||||
|
@ -10,7 +18,7 @@ loop() {
|
|||
#Parse each file in folder
|
||||
folderescaped=${folder////\\/}
|
||||
ky=$(echo "${y}" | sed -e "s/${folderescaped}/https:\/\/${url}/g" -e "s/-[0-9]*\..*\$//g")
|
||||
f=$(mariadb "${db}" -N -B -q -e "select photo from contact where photo like '${ky}%' limit 1")
|
||||
f=$("${dbengine}" "${db}" -N -B -q -e "select photo from contact where photo like '${ky}%' limit 1")
|
||||
if [[ $? -eq 0 && -z ${f} && -f ${y} ]]; then
|
||||
rm -rvf "${y}" &
|
||||
if [[ $(jobs -r -p | wc -l) -ge $(($(getconf _NPROCESSORS_ONLN) * 2)) ]]; then
|
||||
|
@ -28,7 +36,7 @@ date
|
|||
#Go to the Friendica installation
|
||||
cd "${folderavatar}" || exit
|
||||
#indexlength=$((49 + ${#url}))
|
||||
#mariadb "${db}" -e "alter table contact add index if not exists photo_index (photo(${indexlength}))"
|
||||
#"${dbengine}" "${db}" -e "alter table contact add index if not exists photo_index (photo(${indexlength}))"
|
||||
n=0
|
||||
d=0
|
||||
while read -r x; do
|
||||
|
@ -45,5 +53,5 @@ while read -r x; do
|
|||
done < <(find "${x}" -type f)
|
||||
fi
|
||||
done < <(find "${folderavatar}" -depth -mindepth 1 -maxdepth 1 -type d)
|
||||
#mariadb "${db}" -e "alter table contact drop index photo_index"
|
||||
#"${dbengine}" "${db}" -e "alter table contact drop index photo_index"
|
||||
date
|
||||
|
|
Loading…
Add table
Reference in a new issue