Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8622859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:09:10+00:00 2026-06-12T07:09:10+00:00

I’m having some difficulties with this. Basically, for work I need a bash script

  • 0

I’m having some difficulties with this. Basically, for work I need a bash script that backs up a variable number of directories that are stored in a config file.

I’m sure I need to import the list from the config file and just use a loop to copy all the directories across. I have it working for a single directory. My code is below. I’ve cut it down to a minimum.

#!/bin/sh
if [ ! -f ./backup.conf ]
then
echo "Configuration file not found. Exiting!!"
exit
fi
. ./backup.conf

unset PATH

# make sure we're running as root
if (( `$ID -u` != 0 )) ; then { $ECHO "Sorry, must be root.  Exiting..."; exit; } fi ;

# attempt to remount the RW mount point as RW; else abort
$MOUNT -o remount,rw $SOURCEFILE $DESTINATIONFOLDER ;
if (( $? )); then
{
$ECHO "snapshot: could not remount $DESTINATIONFOLDER readwrite";
exit;
}
fi ;

# step 2: create new backup folder:
$MKDIR $FULLPATH


**Loop should go here**
#copy source directories to backup folder
$RSYNC                              \
-va --delete --delete-excluded              \
--exclude-from="$EXCLUDES"              \
$SOURCEFILE $FULLPATH;

The config file is as follows

SOURCE=path
DESTINATION=path2
BACKUPFOLDERNAME=/laptopBackup

My question is what is the best approach to do this task. i.e how should I format the config file to import a variable amount of paths to an array? or is there a better way of doing this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T07:09:11+00:00Added an answer on June 12, 2026 at 7:09 am

    I’d personally do it slightly differently and have my configuration file more of a “control file”. For example:

    /path       /path2     /laptopBackup
    /tmp        /test      /bigmachine
    

    etc.. 1 line per mount, 3 fields per line (source, destination, backupfoldername)

    Then use something like :

    while read SOURCE DESTINATION BACKUPFOLDERNAME
    do
    
    <stuff>
    
    done < ${configfile}
    

    (removed the cat so as not to shame myself further 🙁 )

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I know there's a lot of other questions out there that deal with this
I need a function that will clean a strings' special characters. I do NOT
I have a small JavaScript validation script that validates inputs based on Regex. I
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
Basically, what I'm trying to create is a page of div tags, each has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.