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.

  • Astro 6.0.6
  • Node 22

Last updated: 19.mar.2026

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/<username>/

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

After restoring, verify the site is working:

  1. Check project files exist:

    Terminal window
    ls -la /opt/docker/<project>/
  2. Install dependencies:

    Terminal window
    cd /opt/docker/<project>
    npm install
  3. Build the site:

    Terminal window
    npm run build
  4. Verify dist/ was created:

    Terminal window
    ls -la dist/
  • Keep last 2 backups locally in /home/<username>/
  • Delete backups older than 30 days
  • Test restore quarterly

A sample backup file is available:

  • Store backups in multiple private locations (local + cloud)
  • Consider automated backup scripts with cron