From 9d0c174de18e9a8cd1fa673117d94d5578e85b59 Mon Sep 17 00:00:00 2001 From: Romain PINSOLLE <53913510+TuroYT@users.noreply.github.com> Date: Thu, 21 May 2026 23:07:16 +0200 Subject: [PATCH] snowshare: use mv instead of cp for uploads backup to prevent disk fill (#14558) * snowshare: use mv instead of cp for uploads backup to prevent disk fill Replaces cp -a with mv when backing up and restoring /opt/snowshare/uploads during updates. cp -a duplicated the entire uploads directory on each update, which could fill the disk on instances with large uploads and left stale backup directories accumulating across failed updates. mv is atomic on the same filesystem and avoids any data duplication. Also clears any leftover backup directory before the move to prevent nesting on interrupted updates. Refs TuroYT/snowshare#258 * snowshare: use UPLOAD_DIR env to persist uploads outside install dir Set UPLOAD_DIR=/opt/snowshare_data in the env file so uploads live outside /opt/snowshare and survive CLEAN_INSTALL updates without any backup/restore step. Existing installations are migrated on first update by moving uploads to the new location and appending UPLOAD_DIR to the env file, making the change non-breaking. --- ct/snowshare.sh | 18 +++++++++++------- install/snowshare-install.sh | 2 ++ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/ct/snowshare.sh b/ct/snowshare.sh index 5a3a4f3df..84215ac2d 100644 --- a/ct/snowshare.sh +++ b/ct/snowshare.sh @@ -35,16 +35,20 @@ function update_script() { systemctl stop snowshare msg_ok "Stopped Service" - msg_info "Backing up uploads" - [ -d /opt/snowshare/uploads ] && cp -a /opt/snowshare/uploads /opt/.snowshare_uploads_backup - msg_ok "Uploads backed up" + if ! grep -q '^UPLOAD_DIR=' /opt/snowshare.env 2>/dev/null; then + msg_info "Migrating uploads to persistent directory" + mkdir -p /opt/snowshare_data + if [ -d /opt/snowshare/uploads ] && [ -z "$(ls -A /opt/snowshare_data 2>/dev/null)" ]; then + mv /opt/snowshare/uploads/* /opt/snowshare_data/ 2>/dev/null || true + mv /opt/snowshare/uploads/.[!.]* /opt/snowshare_data/ 2>/dev/null || true + rmdir /opt/snowshare/uploads 2>/dev/null || true + fi + echo "UPLOAD_DIR=/opt/snowshare_data" >>/opt/snowshare.env + msg_ok "Migrated uploads to /opt/snowshare_data" + fi CLEAN_INSTALL=1 fetch_and_deploy_gh_release "snowshare" "TuroYT/snowshare" "tarball" - msg_info "Restoring uploads" - [ -d /opt/.snowshare_uploads_backup ] && rm -rf /opt/snowshare/uploads && cp -a /opt/.snowshare_uploads_backup /opt/snowshare/uploads - msg_ok "Uploads restored" - msg_info "Updating Snowshare" cd /opt/snowshare $STD npm ci diff --git a/install/snowshare-install.sh b/install/snowshare-install.sh index 98c91fee4..e2ae315ae 100644 --- a/install/snowshare-install.sh +++ b/install/snowshare-install.sh @@ -21,12 +21,14 @@ fetch_and_deploy_gh_release "snowshare" "TuroYT/snowshare" "tarball" msg_info "Installing SnowShare" cd /opt/snowshare $STD npm ci +mkdir -p /opt/snowshare_data cat </opt/snowshare.env DATABASE_URL="postgresql://$PG_DB_USER:$PG_DB_PASS@localhost:5432/$PG_DB_NAME" NEXTAUTH_URL="http://localhost:3000" NEXTAUTH_SECRET="$(openssl rand -base64 32)" ALLOW_SIGNUP=true NODE_ENV=production +UPLOAD_DIR=/opt/snowshare_data EOF set -a source /opt/snowshare.env