![]() |
|
Guide Back Up and Restore a Flask App on an aaPanel Server - Printable Version +- AdminsForum (https://adminsforum.com) +-- Forum: Free & open-source control panels (https://adminsforum.com/Forum-free-open-source-control-panels) +--- Forum: aaPanel (https://adminsforum.com/Forum-aapanel) +---- Forum: aaPanel Guides & Tutorials (https://adminsforum.com/Forum-aapanel-guides-tutorials) +----- Forum: aaPanel Backups & Migration Guides (https://adminsforum.com/Forum-aapanel-backups-migration-guides) +----- Thread: Guide Back Up and Restore a Flask App on an aaPanel Server (/Thread-guide-back-up-and-restore-a-flask-app-on-an-aapanel-server) |
Back Up and Restore a Flask App on an aaPanel Server - DEV - 10-14-2026 A backup is useful only when you can rebuild and run the application from it. This SSH-based guide backs up a small Flask project hosted by aaPanel, restores it outside the live website folder and tests it on a separate localhost port. Tested lab: Ubuntu 22.04.5, aaPanel Free 8.0.7 and a Flask/Gunicorn sample. This is a source-and-dependency recovery exercise, not a complete VPS image or a walkthrough of an aaPanel backup plugin. Restore workflow diagram. The live app and the recovery test remain separate. 1. Define what must be recovered Our sample has app.py and requirements.txt and no database, uploads or secret configuration. A real app may also need a consistent database export, uploaded files, environment secrets, Nginx configuration and its startup settings. Inventory those separately before claiming a complete backup. The live project directory is /www/wwwroot/af-flask-lab. Its Gunicorn command uses app:app and binds 127.0.0.1:3200. Record your environment path, Python version, startup user, domain and mapping port in a protected recovery note. 2. Record the application's packages Place a reviewed requirements.txt beside app.py. Our small sample contains: Code: Flask==3.1.3
gunicorn==26.2.03. Create a protected source archive Choose a new archive name so you do not overwrite an older recovery point. From the VPS terminal, the equivalent command for our two-file sample is: Code: tar -czf /www/backup/af-flask-20261014.tar.gz -C /www/wwwroot af-flask-lab/app.py af-flask-lab/requirements.txt
chmod 600 /www/backup/af-flask-20261014.tar.gz
tar -tzf /www/backup/af-flask-20261014.tar.gzDo not publish backup archives inside a website document root. Rebuild the virtual environment rather than assuming a copied environment is portable between server paths or operating systems. Save a protected off-site copy through your approved backup destination; a local archive alone does not protect against losing the VPS. Off-site transfer was not performed in this exercise. 4. Restore into a new isolated directory Use a new directory that does not already contain files: Code: mkdir /www/af-flask-restore-20261014
tar -xzf /www/backup/af-flask-20261014.tar.gz -C /www/af-flask-restore-20261014Compare app.py and requirements.txt with the source copies. For example: Code: sha256sum /www/wwwroot/af-flask-lab/app.py
sha256sum /www/af-flask-restore-20261014/af-flask-lab/app.py5. Build a fresh environment Use a Python version compatible with the application. Our existing lab uses /usr/bin/python3.10; choose a maintained compatible release for a new deployment. Ubuntu's matching venv package must already be installed. Code: python3 -m venv /www/af-flask-restore-20261014/venv
/www/af-flask-restore-20261014/venv/bin/python -m pip install -r /www/af-flask-restore-20261014/af-flask-lab/requirements.txt
/www/af-flask-restore-20261014/venv/bin/python -m pip check6. Run the restored app on a different local port Set permissions only on the isolated restore directory for the intended application user. In our lab that user is www. From an administrator terminal: Code: chown -R www:www /www/af-flask-restore-20261014
cd /www/af-flask-restore-20261014/af-flask-lab
runuser -u www -- /www/af-flask-restore-20261014/venv/bin/gunicorn --workers 1 --bind 127.0.0.1:3202 app:appCode: curl -i http://127.0.0.1:3202/Before using this for a real recovery Test database connectivity, uploads, background jobs, secrets, logging and the expected user workflow. A two-file Flask test cannot establish those properties. Restore missing resources before changing the live domain or project path. Plan cutover and rollback separately; a rehearsal should not overwrite your running deployment. Completion checklist
AdminsForum lab-tested guide. Illustration is a workflow diagram; commands describe the tested SSH recovery method. |