Tired of killing the same old enemies and aliens in the same old ways. Take a break and create a useful script to take the drudgery out of your computer life.
Example of rsync for simple backups with alias's
I have recently been looking into various ways to make backups, both data and full system backups and there are some excellent methods out there. I tried out a few different offerings and found them a tad too un KISS for my simple needs. Besides I like to tinker.
I have my Arch set up with,
Boot in a EFI partition
Root on a partition
Home on a partition
I wanted to make backups of data in my /home and as I am using Arch more for gaming I wanted to make backups of my root partition as linux game data is kept there aswell as in the /home partition. I am not sure what game files are kept where but there seem to be an awful lot of them spread around all over the place> I can not be bothered tracking down what is where and does it need saving so decided to just make backups of whole partitions with some exclusions.
I have an external usb3 dock where I can slot in two sata drives if needed. This is very handy as I can utilise all my older hdd's and newer ssd's. The dock is only turned on when I need to use it. This means that a lot of the backup solutions that offer scheduled automatic backups or cron jobs are not much use to me.
So I settled on using rsync. I made three rsync commands and made alias's for them and they created folders on my backup drive called HISTORY and saved the necessary data to them. The first run of the commands take some time to run, half an hour to three quarters of an hour, as my home is about 80 GB and root is about 38 GB, boot is a mere 250 MB. On subsequent runs only a couple of minutes is needed, time depends mainly on how many different browsers I have used and how many updates pacman has done.
These are the alias commands,
Code:
alias bback="sudo rsync -vaAXHShix --delete /boot/ /run/media/bloodaxe/HISTORY/BOOT"
alias sback="sudo rsync -vaAXHShix --delete --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/home/","/var/lib/dhcpcd/*","/lost+found"} / /run/media/bloodaxe/HISTORY/SYSTEM"
alias hback="rsync -vaHAXShix --delete --exclude=slots --exclude=tempfile --exclude=.local/share/Trash --exclude=projects --exclude=.local/share/gvfs-metadata --exclude=/home/*/.gvfs /home/bloodaxe/ /run/media/bloodaxe/HISTORY/HOME"
here is a sample output after they have run,truncated as the output can be quite long.
Code:
16:54:14-->Wed May 27-->~
-->bback
sending incremental file list
*deleting EFI/BOOT/icons-backup/os_trusty.png
*deleting EFI/BOOT/icons-backup/os_mac.png
*deleting EFI/BOOT/icons-backup/mouse.png
.d..t...... EFI/BOOT/icons-backup/
sent 7.62K bytes received 151 bytes 15.55K bytes/sec
total size is 82.04M speedup is 10,555.11
16:54:24-->Wed May 27-->~
-->sback
sending incremental file list
.d..t...... dev/
.d..t...... etc/
>f..t...... etc/ld.so.cache
.d..t...... root/
>f.st...... root/.bash_history
.d..t...... tmp/
.d..t...... usr/
.d..t...... usr/bin/
>f..t...... usr/bin/ffmpeg
>f..t...... usr/bin/ffplay
>f..t...... usr/include/libavcodec/avcodec.h
*deleting var/lib/pacman/local/ffmpeg-1:4.2.3-1/mtree
*deleting var/lib/pacman/local/ffmpeg-1:4.2.3-1/files
*deleting var/lib/pacman/local/ffmpeg-1:4.2.3-1/desc
*deleting var/lib/pacman/local/ffmpeg-1:4.2.3-1/
.d..t...... var/lib/pacman/
.d..t...... var/lib/pacman/local/
cd+++++++++ var/lib/pacman/local/ffmpeg-1:4.2.3-2/
>f+++++++++ var/lib/pacman/local/ffmpeg-1:4.2.3-2/desc
sent 310.49M bytes received 39.60K bytes 7.48M bytes/sec
total size is 39.58G speedup is 127.45
16:55:14-->Wed May 27-->~
-->hback
sending incremental file list
.d..t...... ./
>f.st...... .bash_history
>f.st...... client_state.xml
>f.st...... client_state_prev.xml
>f..t...... daily_xfer_history.xml
>f.st...... job_log_www.worldcommunitygrid.org.txt
*deleting .cache/mozilla/firefox/2wtpmdoa.default/cache2/ce_YSwJaHR0cHM6Ly93d3cuYW1hem9uLmNvLnVr
.d..t...... notices/
>f..t...... notices/archive_www.worldcommunitygrid.org_viewNoticesRSSFeed.action.xml
>f..t...... notices/www.worldcommunitygrid.org_viewNoticesRSSFeed.action.xml
sent 43.75M bytes received 27.91K bytes 1.79M bytes/sec
total size is 78.03G speedup is 1,782.43
16:55:47-->Wed May 27-->~
-->
I may have gone overboard with the rsync switches but I wanted to cover all the bases. I included the " i " option as it gives a nice output of what is going on with each file. You get a "f" for a file "d" for directory,the "s" and"t" tell you size and time has altered and "deleting" is obvious.
I still have some fine tuning to do as I run
BOINC and there are a lot of small files relating to that in /home that I do not need to backup.Adding them to the rsync command would make for a very long command so I will use the exclude from text option at some time later on.
Whilst searching for information I came across information for using bash to run several commands one after the other so I created a alias to run all three backup commands like so,
Code:
alias allback="bback && sback && hback"
I have to have a separate command for boot as it is on its own partition and I have included the "x" option which stops rsync crossing filesystem boundaries when recursing. Good job I checked the contents of the system backup whilst doing a trial.
Also if playing around with rsync it is best to use the " n " dry run option first before doing a real run through.
When I have time I am going to see if I can successfully transfer the three backups to another ssd and get a functional system running. According to the Arch wiki that should be possible. I need bit of a rest for now so will try at some future date.