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.
What Gets Backed Up
Section titled “What Gets Backed Up”| Include | Exclude |
|---|---|
src/ - source code | node_modules/ - reinstallable |
public/ - static assets | dist/ - 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 |
Prerequisites
Section titled “Prerequisites”- 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”cd /opt/dockerStep 2 - Create the Backup
Section titled “Step 2 - Create the Backup”Replace <project> with your project folder name and <date> with current date:
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>Example
Section titled “Example”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 buckoStep 3 - Move Backup to Home Directory
Section titled “Step 3 - Move Backup to Home Directory”mv <project>-<date>.tar.gz /home/<user>/Example
Section titled “Example”mv bucko-18-mar-2026.tar.gz /home/samob/Step 4 - Verify Backup
Section titled “Step 4 - Verify Backup”Check the backup size and contents:
ls -lh /home/<user>/<project>-<date>.tar.gztar -tzvf /home/<user>/<project>-<date>.tar.gz | head -20Step 5 - Download Backup (Optional)
Section titled “Step 5 - Download Backup (Optional)”To download the backup to your local machine:
scp <user>@<server_ip>:/home/<user>/<project>-<date>.tar.gz .Restore from Backup
Section titled “Restore from Backup”To restore the project from a backup:
# Extract to temporary directory firstmkdir -p /tmp/restoretar -xzvf /home/<user>/<project>-<date>.tar.gz -C /tmp/restore
# Copy to destinationcp -r /tmp/restore/<project> /opt/docker/
# Install dependenciescd /opt/docker/<project>npm install
# Build and verifynpm run buildDownload Example Backup
Section titled “Download Example Backup”A sample backup file is available:
- bucko-18-mar-2026.tar.gz - 129MB
Next Steps
Section titled “Next Steps”- Store backups in multiple locations (local + cloud)
- Consider automated backup scripts with cron
- Document your restore process and test it periodically