How to Create Complete Website Backups on Linux/Mac Using Command‑Line Tools
This guide walks you through the essential prerequisites, SSH connection, database export, tar compression, optional config/log backups, and final download steps to reliably back up a website on Linux or macOS using only free command‑line utilities.
Necessary Conditions
Your server must have the required software and certificates installed.
Server software
tar
Client software
SSH (to create/delete backup files) SCP (to download backup files) Terminal (e.g., gnome‑terminal to run commands)
Required information
Server IP and SSH key Database credentials Website root directory (and any directories to include or exclude) Database type: MySQL, PostgreSQL, or SQLite
Backup Creation Steps
After connecting your computer to the server, you can quickly back up the site via command line.
Connect to the server via SSH
Open a terminal and run the SSH command to log into your server. Once connected, commands you type are executed on the remote host.
Create a directory named backup on the server (e.g., /home/username/backup) to store all backup files.
If you do not know the web root, you can find it in your cPanel account.
Use mkdir -p /home/username/backup to create the folder, then create subfolders db, core, logs, and conf.
Export Database
Command‑line tools can dump databases without extra software.
For MySQL:
For PostgreSQL:
These commands prompt for username and password; the dump file is saved in /home/username/backup/db/ .
For SQLite, simply copy the database file:
Create Tar of Website Files
Compress the website core files using tar. Assuming the site resides in /home/username/html:
To exclude unnecessary directories (e.g., cache), use the --exclude option:
Optional: Backup Configuration or Log Files
Backing up config and log files can be valuable for future reference. Add multiple paths to a single tar command, using backslashes (\) to split the command across lines.
Ensure the server has the required software; otherwise, restoring config files may fail.
Final Backup
All necessary files are now under /home/username/backup. Create a final tar archive and download it via scp:
The command creates latest.backup.tar. After downloading, you can safely delete the backup on the server:
Warning! Verify file and folder paths before deletion; recovery after command‑line removal is difficult.
Conclusion
The website backup process is now complete. While this is not a comprehensive solution, it provides a solid foundation for learning backup techniques in information security.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
