Using SSH to Backup Files
Backups can be set up via cPanel, WHM, or Liquid Web account for entire server. For specific files, use CLI via SSH, but be cautious as root user can alter/delete anything without confirmation.
Backups can be set up via cPanel, WHM and in your Liquid Web account for your entire server, but if you’re looking to backup specific files you’ve created you will need to use the Command Line Interface (CLI) via SSH. If you’ve never logged in via SSH, learn how in our article Logging into Your Server via Secure Shell (SSH).
Warning: |
Logging into a server as root is a powerful but potentially dangerous tool. The root user is allowed to change/delete practically everything in a server without warning or confirmation of changes being made. |
- Once you’ve logged in via SSH, enter the following command to view all the files on your server:
ls -lah
- This will list all the files in human-readable format. From here, you can choose the files you want to backup.
total 176K dr-xr-x---. 13 root root 4.0K Sep 28 10:34 . dr-xr-xr-x. 19 root root 4.0K Aug 8 10:29 .. 1 root root 35 Sep 28 10:34 anothersample.txt 1 root root 2.4K Sep 28 10:35 .bash_history -rw-r--r--. 1 root root18 Dec 28 2013 .bash_logout -rw-r--r--. 1 root root 176 Dec 28 2013 .bash_profile 1 root root 360 May 3 12:40 .bashrc drwx------ 4 root root 4.0K May 3 12:01 .cpanel drwxr-xr-x 4 root root 4.0K Jun 1 15:53 cpanel3-skel -rw-r--r--. 1 root root 100 Dec 28 2013 .cshrc -rw------- 1 root root 1 May 3 12:01 .forward drwx------ 2 root root 4.0K May 3 11:35 .gnupg drwx------ 2 root root 4.0K May 25 15:26 .HttpRequest drwx------ 4 root root 4.0K May 25 15:26 .MirrorSearch -rw------- 1 root root 42 May 25 15:16 .my.cnf drwxr-xr-x 2 root root 4.0K Jun 20 14:51 perl5 -rw-r--r-- 1 root root 39K May 3 12:15 php.ini.new -rw-r--r-- 1 root root 39K May 3 12:15 php.ini.orig drwxr----- 3 root root 4.0K May 3 12:17 .pki drwxr-xr-x 2 root root 4.0K Sep 28 09:51 .razor -rw------- 1 root root 1.0K May 3 11:43 .rnd -rw-r--r-- 1 root root 84 Sep 28 10:34 sample.txt drwx------ 3 root root 4.0K May 3 11:41 .spamassassin drw------- 2 root root 4.0K Aug 4 14:47 .ssh -rw-r--r--. 1 root root 129 Dec 28 2013 .tcshrc drwxr-xr-x 3 root root 4.0K Sep 27 22:58 tmp
- In this example, I will backup the file sample.txt. In order to backup the file, type the following command:
cp sample.txt sample.bak
- This copies the file sample.txt and creates a new file called sample.bak. Another use of the ls -lah command will show you the new file:
total 180K dr-xr-x---. 13 root root 4.0K Sep 28 10:39 . dr-xr-xr-x. 19 root root 4.0K Aug 8 10:29 .. -rw-r--r-- 1 root root 35 Sep 28 10:34 anothersample.txt -rw------- 1 root root 2.4K Sep 28 10:35 .bash_history -rw-r--r--. 1 root root 18 Dec 28 2013 .bash_logout -rw-r--r--. 1 root root 176 Dec 28 2013 .bash_profile -rw-r--r--. 1 root root 360 May 3 12:40 .bashrc drwx------ 4 root root 4.0K May 3 12:01 .cpanel drwxr-xr-x 4 root root 4.0K Jun 1 15:53 cpanel3-skel -rw-r--r--. 1 root root 100 Dec 28 2013 .cshrc -rw------- 1 root root 1 May 3 12:01 .forward drwx------ 2 root root 4.0K May 3 11:35 .gnupg drwx------ 2 root root 4.0K May 25 15:26 .HttpRequest drwx------ 4 root root 4.0K May 25 15:26 .MirrorSearch -rw------- 1 root root 42 May 25 15:16 .my.cnf drwxr-xr-x 2 root root 4.0K Jun 20 14:51 perl5 -rw-r--r-- 1 root root 39K May 3 12:15 php.ini.new -rw-r--r-- 1 root root 39K May 3 12:15 php.ini.orig drwxr----- 3 root root 4.0K May 3 12:17 .pki drwxr-xr-x 2 root root 4.0K Sep 28 09:51 .razor -rw------- 1 root root 1.0K May 3 11:43 .rnd -rw-r--r-- 1 root root 84 Sep 28 10:39 sample.bak -rw-r--r-- 1 root root 84 Sep 28 10:34 sample.txt drwx------ 3 root root 4.0K May 3 11:41 .spamassassin drw------- 2 root root 4.0K Aug 4 14:47 .ssh -rw-r--r--.1 root root 129 Dec 28 2013 .tcshrc drwxr-xr-x 3 root root 4.0K Sep 27 22:58 tmp
If you need to backup more than one file or need to backup full directories, see our article Exploring the rsync Utility.