Knowledge Base Hub

Browse through our helpful how-to guides to get the fastest solutions to your technical issues.

Home  >  How-Tos  >  Learn how to backup a file before editing it
Top Scroll

Learn how to backup a file before editing it

 3 min

In this knowledge base post, we will see how to backup a file from the cPanel File Manager, over FTP, or via SSH on a VPS or a dedicated server.

Backup a file in cPanel File Manager

Using the steps updated below, you can simply back up a file by using the cPanel File Manager.

Step 1: Login to your cPanel.

Click on file manager

Step 2: Under the Files section, click on File Manager.

Click on file manager settings

Step 3: In the top right-hand corner, click on Settings. Select the Document Root for – option, and choose your domain from the drop-down.

Step 4: Make sure that Show Hidden Files is selected.

Step 5: Then click Save.

Step 6: Right-click on the file you would like to backup and select Copy from the drop-down.

Type in the name and confirm the path of the file to copy

Step 7: Copy the full path from the Type the path you wish to copy field, for example, this would be:

copy-window

/public_html/admin/config.php

In the field below that with the house icon, paste the full path you copied and then append -BAK to the end. For example, this should look like:

/public_html/admin/config.php-BAK

Finally, click on Copy File(s)

confirm-backup

Step 8: Now you should have a backed up copy of your original file, and you can reverse the same steps if you’d like to have your config.php-BAK file copied over the config.php file to restore the data that you have backed up.

Backup a file in FTP client

Below updated are the steps that you can simply use with FTP client to retrieve a local copy of a file for backup purposes. Then you can simply re-upload that backed up file to the server if something goes wrong with the original file.

Step 1: In your FTP client, navigate to the file you would like to backup in the right-hand server pane, in the left-hand pane, navigate to a local folder on your computer you would like to backup your file to.

Step 2: Drag over your file from the right-hand server pane over to your local folder on the left.

filezilla-drag-file-to-local-folder

Step 3: If you wanted to restore the file you have backed up, simply reverse the process and drag the backed up file from your local folder on the left to the remote server directory on the right.

filezilla-drag-file-to-remote-server

Step 4: Your FTP client will present you with a Target file already exists pop-up, simply choose Overwrite as the Action, and then click on OK.

filezilla-confirm-overwrite-file

Backup a file via SSH

To follow these steps, you will need to have SSH access to your server.

Step 1: Login to your server via SSH.

Step 2: Here are 3 example commands you could use to backup the file /home/userna5/public_html/admin/config.php to the same directory as config.php-BAK:

cp -frp /home/userna5/public_html/admin/config.php{,-BAK}
cp -frp /home/userna5/public_html/admin/config.php /home/userna5/public_html/admin/config.php-BAK
cd /home/userna5/public_html/admin/
cp -frp config.php config.php-BAK

Once you are done, you can see the backed up file:

userna5@server [/home]# ls -l /home/userna5/public_html/admin/
total 16
drwxr-xr-x 2 userna5 userna5 4096 Dec 20 14:45 ./
drwxr-xr-x 3 userna5 userna5 4096 Dec 20 13:59 ../
-rw-r--r-- 1 userna5 userna5 395 Dec 20 14:34 config.php
-rw-r--r-- 1 userna5 userna5 395 Dec 20 14:34 config.php-BAK

After taking a look at these steps, we hope that now you can backup a file on your server using a few different methods. This will help you to make sure that you always have a good file if you need to revert back in case you encounter any problem after editing the original file.

Related: Learn how to Backup or Export the Database from SSH.

For our Knowledge Base visitors only
Get 10% OFF on Hosting
Special Offer!
30
MINS
59
SECS
Claim the discount before it’s too late. Use the coupon code:
STORYSAVER
Note: Copy the coupon code and apply it on checkout.