How to Create Complete Website Backups on Linux/Mac Using Command Line
This guide walks you through the essential steps, tools, and commands needed to securely back up a website—including files, databases, and optional configuration logs—using SSH, SCP, and tar on Linux or macOS systems.
Necessary Conditions
Your server must have the required software and certificates installed.
Software on the server
tar
Software on your computer
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
Once your computer is connected to the server via SSH, you can perform the backup using command-line tools.
Connect to the server via SSH
Open a terminal and run the SSH command to log into your server.
After logging in, create a new folder named backup on the server (any location that is not publicly accessible).
If your web app root is /home/username/html , you can create /home/username/backup to store the backup files.
Find the web root directory in your cPanel if you are unsure.
The root directory shown is /home/ma658tvk.
Create the backup directory with mkdir -p /home/username/backup.
Inside this folder, create subdirectories db, core, logs, and conf.
Note the -p option for mkdir prevents errors if the directory already exists.
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 Archive of Website Files
Install tar on the server and compress the core files.
Assuming the site is at /home/username/html, run:
To exclude the cache directory, use the --exclude option:
Optional: Backup Configuration or Log Files
Include additional config or log files by adding their paths to the tar command, using backslashes (\) to split the command across lines.
Ensure the correct software is installed on the backup server; restoring config files is simply copying them back.
Final Backup
After preparing all files under /home/username/backup, create a final tar archive and download it.
The command creates latest.backup.tar. Exit the SSH session with exit.
Download via SCP
Use scp to transfer the tar file to your local machine, e.g., /home/username/backups/domainname/, and rename it with a timestamp.
Delete Backup from Server
After confirming the backup is safe locally, remove the server copies:
Warning! Verify file and folder paths before deletion; recovery after command‑line removal is difficult and may become impossible over time.
Finally, exit the server with exit.
Conclusion
The website backup process is now complete. While not a full solution, it provides a solid foundation for learning backup techniques in the information‑security field.
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.
