The purpose of this script is to open and mount the truecrypt container and then go about its job syncing all the desired files and directories to their selected destinations. This script handles files and directories from anywhere to anywhere, so you can choose many things to backup to specific locations within your container to maintain organization.
This makes backups very quick and easy after you get your paths in the variables section set. What is great about rsync is by default does not copy a file if it exists without having been changed, by default this behavior is based on time stamps and file size, so this means you can run this script and only what has changed will be copied.
Setting the variables
Make sure to double quote each entry and then space it. Directories should end in a forward slash (/). So it will look like so:
Then the destinationArray holds the path to the destination for the corresponding entry in the sourceArray. So you're specifying where you want your Documents to go an example. It will look like so:
Right now $media_path might not make much sense but it is the variable that holds the crypt name appended to /media/ as that is what the crypt will be mounted as. This isn't required for you to use, just in the future if you ever change the name of your crypt then it will save you editing the destinationArray to reflect the correct locations so it is a good idea to use the $media_path variable.
The reason it is done this way in an intentional design decision to enable you to choose multiple files and directories to backup with ease. This is an easy way to implement that without making it a pain for the user to use.
How to use
- Lets get the source
git clone https://github.com/jeekkd/rsync-truecrypt.git && cd rsync-truecrypt
- This will make the script readable, writable, and executable to root and your user.
sudo chmod 770 rsync_truecrypt.sh
- Open the script in your text editor of choice. You need to edit the variables in the highlighted variables section near the top.
- You will want to make sure you've saved, then launch the script by doing the following:
sudo bash rsync_truecrypt.sh
Note: Make sure you've installed the 'rsync' and 'cryptsetup' package for your distribution
Additionally, here is how you can add the script to be globally runnable. This is super convenient since you can merely type something such as the following and have the script run:
Here's how we can do this:
# Syntax of doing so: sudo ln <script location/script name> /usr/local/bin/<name you want to type to launch the script> # Realistic example: sudo ln /home/<user>/rsync_truecrypt.sh /usr/local/bin/backup