Backup a file before editing Updated on August 16, 2021 by InMotion Hosting Contributor 3 Minutes, 18 Seconds to Read 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. Login to your cPanel. Under the Files section, click on File Manager. In the top right hand corner, click on Settings. Select the Document Root for: option, and choose your domain from the drop-down. Ensure that Show Hidden Files is selected. Then click Save. Right-click on the file you’d like to backup, and select Copy from the drop-down. 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) 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. 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. Drag over your file from the right-hand server pane over to your local folder on the left. 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. 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. Login to your server via SSH. 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. Share this Article 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 Related Articles Maintenance ecbiz111 failover to backup hardware Emergency File System Recovery on ld143 Emergency File System Recovery on biz112 Emergency File System Recovery on biz123 How to Install Nextcloud on Ubuntu 18.04 LTS Protect an Archived Backup The Complete Guide to cPanel Backups Backup Manager WHM Guide for VPS/Dedicated Servers How to Keep Regular Backups for Reseller Accounts Storing Your Backups with Amazon S3 via WHM