Skip to content

Backup Static Astro Site

This guide explains how to create a clean backup of a static Astro site, excluding unnecessary files like node_modules and .git.

IncludeExclude
src/ - source codenode_modules/ - reinstallable
public/ - static assetsdist/ - build output
package.json - dependencies manifest.git/ - version control
Config files (astro.config.mjs, tsconfig.json).env files - secrets
Dockerfile, compose.yaml*.tar.gz - old backups
  • Access to the server hosting the Astro project
  • Project directory (e.g., /opt/docker/<project>/)

Step 1 - Navigate to Project Parent Directory

Section titled “Step 1 - Navigate to Project Parent Directory”
Terminal window
cd /opt/docker

Replace <project> with your project folder name and <date> with current date:

Terminal window
tar -czvf <project>-<date>.tar.gz \
--exclude='node_modules' \
--exclude='dist' \
--exclude='.git' \
--exclude='*.tar.gz' \
--exclude='test-results' \
--exclude='playwright-report' \
--exclude='.env' \
--exclude='.env.*' \
--exclude='.astro' \
-C /opt/docker <project>
Terminal window
tar -czvf bucko-18-mar-2026.tar.gz \
--exclude='node_modules' \
--exclude='dist' \
--exclude='.git' \
--exclude='*.tar.gz' \
--exclude='test-results' \
--exclude='playwright-report' \
--exclude='.env' \
--exclude='.env.*' \
--exclude='.astro' \
-C /opt/docker bucko
Terminal window
mv <project>-<date>.tar.gz /home/<user>/
Terminal window
mv bucko-18-mar-2026.tar.gz /home/samob/

Check the backup size and contents:

Terminal window
ls -lh /home/<user>/<project>-<date>.tar.gz
tar -tzvf /home/<user>/<project>-<date>.tar.gz | head -20

To download the backup to your local machine:

Terminal window
scp <user>@<server_ip>:/home/<user>/<project>-<date>.tar.gz .

To restore the project from a backup:

Terminal window
# Extract to temporary directory first
mkdir -p /tmp/restore
tar -xzvf /home/<user>/<project>-<date>.tar.gz -C /tmp/restore
# Copy to destination
cp -r /tmp/restore/<project> /opt/docker/
# Install dependencies
cd /opt/docker/<project>
npm install
# Build and verify
npm run build

A sample backup file is available:

  • Store backups in multiple locations (local + cloud)
  • Consider automated backup scripts with cron
  • Document your restore process and test it periodically