Bash backup script. Read list of files

Apologies if I’m kind of a bash novice!

I’ve created a backup script that works fine. However, I want to simplify it a bit, by either reading and inserting a list of files into rsync or reading the list of files from another script file into rsync.

Reason being so I can easily change the list of files without rewriting the script. As right now I have all the list of files written in each rsync command.


This is basically what I have written now

# !/bin/bash
bakdir = ~/backup
mkdir -p $bakdir

mkdir -p "$bakdir"/Documents
cd ~/Documents
rsync -a --progress Document1.doc Document2.doc "$bakdir"/Documents

mkdir -p "$bakdir"/Stuff
cd ~/Stuff
rsync -a --progress Folder1 Document.doc "$bakdir"/Stuff

What I want to achieve

mkdir -p "$bakdir"/Documents
cd ~/Documents


rsync -a --progress $list1 "$bakdir"/Documents

mkdir -p "$bakdir"/Stuff
cd ~/Stuff


rsync -a --progress $list2 "$bakdir"/Stuff

Tried searching for a question similar to this and can’t find anything.

Thank you in advance.

Source: bash

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.