tar-based backups
tar-based backups
v25-10-30This procedure covers how to to create a tar file from a directory tree called /srv/xxxx-xxxx preserving ownership & permissions and to restore to an existing empty directory with the same name in another machine.
For more information see: https://manpages.ubuntu.com/manpages/noble/man1/tar.1.html
Prerequisites
- The directory
/srv/xxxx-xxxxmust not have an application conneted updating data. If this is the case, stop the application or make an snapshot. - Destination directory with enough capacity for backup tar file.
- Sudo privileges to access the tree and preserve ownership and permissions.
Backup procedure (Source machine)
- Go to a safe location to store the archive (e.g., /tmp or your home):
# Temp directorycd /tmp# Home directorycd ${HOME}
- Create a tar archive preserving ownership & permissions:
sudo tar -cvpzf xxxx-xxxx.tar.gz /srv/xxxx-xxxx
- Transfer the archive to the target machine (example with scp):
scp /tmp/xxxx-xxxx.tar.gz user@target.domain.com:/tmp/
Restore procedure (Target machine)
- Make sure the target directory exists and is empty:
sudo ls -lah /srv/xxxx-xxxx
- Move into root directory
/to avoid nesting issues:
sudo tar -xvpzf /tmp/xxxx-xxxx.tar.gz -C /
- Verify contents:
sudo ls -lah /srv/xxxx-xxxx