How to Backup Directory on Ubuntu Server

Learn how to backup a directory on ubuntu so you can store all your files in one quick command. This has saved me lots of time.

In order for you to backup a directory follow this short tutorial to get started

tar -zcvpf /[Backup_Location]/[Backup_Filename] /[User_Home_Directory_Location]

I have detailed here the explanation of the commands for better understanding.

  • z : Compress the backup file with ‘gzip’ to make it a small size.
  • c : Create a new backup archive.
  • v : verbosely list files that are processed.
  • p : Preserves the permissions of the files put in the archive for later restoration.
  • f : use archive file or device ARCHIVE.

So how do you use this?

We are going to backup the directory of user ploi this is how you can do it

tar -zcvpf /backup/ploi-backup-$(date +%d-%m-%Y).tar.gz /home/ploi

If you want to exclude folders

tar --exclude='/home/ploi/test-folder' -zcvpf /backup/ploi-backup-$(date +%d-%m-%Y).tar.gz /home/ploi