Backup a file before editing

In this article I’m going to go over a few ways in which you can backup a file for your website. That way if you directly modified the original file on the server and made a mistake, you can revert to your saved copy.

Many times you might need to modify a config, include, or template file for your software that you’re running on your website. In most cases it is much easier to just directly modify these files instead of editing a local copy and then re-uploading that to the server.

In this article I’ll review how you can backup a file from the cPanel File Manager, over FTP, or via SSH if you happen to have a VPS or dedicated server.

Backup a file in cPanel File Manager

Using the steps below I’ll show you how you can easily back up a file using the cPanel File Manager.

  1. Login to your cPanel.
  2. Click on file manager

    Under the Files section, click on File Manager.

  3. Click on file manager settings

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

  4. Ensure that Show Hidden Files is selected.
  5. Then click Save.
  6. Select the file to copy

    Right-click on the file you’d like to backup, and select Copy from the drop-down.

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

    Copy the full path from the Type the path you wish to copy field, in our example this would be:

    /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. In our example this should look like:

    /public_html/admin/config.php-BAK
    Finally click on Copy File(s)

  8. Confirm that the file is backed up

    You should now 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 backed up data.

Backup a file in FTP client

Following the steps below you can also simply use a 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 in the event that something went wrong with the original file.

  1. In your FTP client navigate to the file you’d like to backup in the right-hand server pane, in the left-hand pane navigate to a local folder on your computer you’d like to backup the file to.
  2. filezilla drag file to local folder

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

  3. filezilla drag file to remote server

    If you wanted to restore your backed up file, 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.

  4. filezilla confirm overwrite file

    Your FTP client will more than likely present you with a Target file already exists pop-up, simply choose Overwrite as the Action, then click on OK.

Backup a file via SSH

To follow along with the steps below you’ll need to have SSH access to either your VPS or dedicated server.

  1. Login to your server via SSH.
  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

    You should then be able to see the backed up file:

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

You should now understand how you can backup a file on your server using a few different methods. This will help ensure that you always have a good file to revert back to incase any problem are encountered after you’ve edited the original file.

InMotion Hosting Contributor
InMotion Hosting Contributor Content Writer

InMotion Hosting contributors are highly knowledgeable individuals who create relevant content on new trends and troubleshooting techniques to help you achieve your online goals!

More Articles by InMotion Hosting

Was this article helpful? Join the conversation!

Server Madness Sale
Score Big with Savings up to 99% Off

X