Introduction
cPanel offers a GUI tool, File and Directory Restoration, for restoring individual files. However, it may be preferable to manually extract individual files from a backup via the command line.
Procedure
- Log into your server via SSH or terminal.
- Execute the following command to locate the file in the backup. Please replace $filename with the name of the file to be restored.
tar -tvf /path/to/backup/file.tar.gz | grep $filename
For example, if you needed to replace a corrupt shadow file for your domain's mail accounts, you would see the following output for the tar command.
[root@server ~]cPs# tar -tvf /backup/2022-05-15/accounts/username.tar.gz|grep shadow
-rw------- root/root 106 2022-05-15 02:01 username/shadow
-rw------- root/root 0 2022-05-15 02:01 username/digestshadow
-rw-r----- username/username 253 2021-10-16 13:24 username/homedir/etc/domain.tld/shadow
[root@server ~]cPs# - Once you have located the file you need to restore, use the following command to extract that file.
tar -zxvf /path/to/backup/file.tar.gz path/to/file/within/backup.txt
Continuing with the above example, you will see the following output when you extract the file.
[root@server ~]cPs# tar -zxvf /backup/2022-05-15/accounts/username.tar.gz username/homedir/etc/domain.tld/shadow
username/homedir/etc/domain.tld/shadow
[root@server ~]cPs#
Note: The file will be extracted to the same path listed in the backup relative to the current working directory.
[root@server ~]cPs# find . -name shadow
./username/homedir/etc/domain.tld/shadow
[root@server ~]cPs#
Comments
0 comments
Article is closed for comments.