Back up your home directory with this simple script. This will concatenate all of your files into one tar archive, then compress it into a gzipped file.
Firstly, install the required applications.
┌──(john㉿DESKTOP-PF01IEE)-[~/Documents] └─$ sudo apt install pv pigz |
This is the backup script I am using. This will back up the entire home directory in a date-stamped archive.
┌──(john㉿DESKTOP-PF01IEE)-[~/Documents] #!/bin/sh SERVER_BACKUP_FILENAME=server-`date '+%Y%m%d-%H:%M:%S'`.tar.gz tar --acls --xattrs -cpf - /home/$LOGNAME | pv -cN tar | pigz -9 | pv -cN gzip > $SERVER_BACKUP_FILENAME |
Now the archiving can begin. This is very fast and creates a nice date stamped file that can be backed up on a removable drive or a secure online backup platform.
┌──(john㉿DESKTOP-PF01IEE)-[~/Documents] └─$ ./my.sh tar: Removing leading `/' from member names tar: 110KiB 0:00:00 [ 751KiB/s] [ <=> ] gzip: 17.1KiB 0:00:00 [ 113KiB/s] [ <=> ] gzip: 100MiB 0:00:04 [23.1MiB/s] [ <=> |
This is what I got when I backed up an Ubuntu home directory. This works very well.
┌──(john㉿DESKTOP-PF01IEE)-[~/Documents] total 32K drwxr-xr-x 2 john john 4.0K Jan 6 07:32 . drwxr-xr-x 7 john john 4.0K Jan 6 07:28 .. -rwxr-xr-x 1 john john 181 Jan 6 07:28 my.sh -rw-r--r-- 1 john john 18K Jan 6 07:29 server-20220106-07:29:11.tar.gz |
The rsync utility may also be used to back up your home directory, this is very easy to use.
This is an easy way to backup a home directory, this will backup all files in the /home folder of your user and place it all in a folder named as your username.
┌──(john㉿DESKTOP-PF01IEE)-[~/Documents] └─$ rsync -avh --progress /home/$LOGNAME /mnt/c/Users/Intel\ i5/Documents/backups/$LOGNAME/ sending incremental file list created directory /mnt/c/Users/Intel i5/Documents/backups/john john/ john/.bash_history 7.13K 100% 0.00kB/s 0:00:00 (xfr#1, to-chk=32/34) john/.bash_logout 220 100% 214.84kB/s 0:00:00 (xfr#2, to-chk=31/34) john/.bashrc 5.35K 100% 5.10MB/s 0:00:00 (xfr#3, to-chk=30/34) john/.bashrc.original 3.53K 100% 3.36MB/s 0:00:00 (xfr#4, to-chk=29/34) john/.profile 807 100% 788.09kB/s 0:00:00 (xfr#5, to-chk=28/34) john/.selected_editor 72 100% 70.31kB/s 0:00:00 (xfr#6, to-chk=27/34) john/.viminfo 4.40K 100% 4.20MB/s 0:00:00 (xfr#7, to-chk=26/34) john/.zshrc 10.64K 100% 10.15MB/s 0:00:00 (xfr#8, to-chk=25/34) john/index.html 14.07K 100% 13.42MB/s 0:00:00 (xfr#9, to-chk=24/34) john/.cache/ john/.cache/mc/ john/.cache/mc/Tree 35 100% 0.36kB/s 0:00:00 (xfr#10, to-chk=17/34) john/.cache/mc/mcedit/ john/.config/ john/.config/mc/ john/.config/mc/ini 3.50K 100% 36.36kB/s 0:00:00 (xfr#11, to-chk=13/34) john/.config/mc/panels.ini 0 100% 0.00kB/s 0:00:00 (xfr#12, to-chk=12/34) john/.config/mc/mcedit/ john/.config/powershell/ john/.config/powershell/Microsoft.PowerShell_profile.ps1 1.34K 100% 13.97kB/s 0:00:00 (xfr#13, to-chk=10/34) john/.java/ john/.java/.userPrefs/ john/.java/.userPrefs/burp/ john/.java/.userPrefs/burp/prefs.xml 305 100% 3.17kB/s 0:00:00 (xfr#14, to-chk=7/34) john/.local/ john/.local/share/ john/.local/share/mc/ john/.local/share/mc/filepos 100 100% 1.04kB/s 0:00:00 (xfr#15, to-chk=4/34) john/.local/share/mc/history 939 100% 9.76kB/s 0:00:00 (xfr#16, to-chk=3/34) john/.local/share/mc/mcedit/ john/Documents/ john/Documents/my.sh 181 100% 1.88kB/s 0:00:00 (xfr#17, to-chk=1/34) john/Documents/server-20220106-07:29:11.tar.gz 17.53K 100% 182.08kB/s 0:00:00 (xfr#18, to-chk=0/34) sent 72.05K bytes received 497 bytes 48.36K bytes/sec total size is 70.15K speedup is 0.97 |