I need help with my backup script

This scripts compresses the files o.k. in their respective directories.

I went from resync to using cp.

However, not all of them are copied to the backup directories that are on a second platter drive.

Could someone help me?

DOG_ATTACKS="home/andy/Dog_Attack/"

Backup_Directory="/media/andy/Maxtor/Backup/Ubuntu_Mate_24.04/"

DOCS="/home/andy/Documents/" # shell variable
SCRIPTS="/home/andy/bin/"
HOME="/home/andy/"
ICONS="/home/andy/Icons"
MY_Sounds="/usr/share/sounds/My_Sounds/"
THUNAR="/home/andy/.config/Thunar/"
Music="/home/andy/Music/"
FedEx="/home/andy/FedEx/"

#
cd $THUNAR
tar -cf Thunar_Custom_Actions.tar uca.xml
cp Thunar_Custom_Actions.tar $Backup_Directory
#--------------------------------
cd /home/andy/Dog_Attack/
tar -cf Dog_Attack_Documentation.tar *.png *.pdf *.odt *.jpg *.mp4
cp Dog_Attack_Documentation.tar $Backup_Directory
# 
#-----------------------------------------------
cd /home/andy/Icons
tar -cf Icons.tar  
#cp Icons.tar $Backup_Directory

cd $DOCS
tar -cf Ubuntu_Documents.tar *.txt *.doc *.rtf *.html *.png *.pdf *.odt *.ods *.odg *.csv *.xls *.jpg *.PDF *.docx *.otg *.doc
## ONLY copy file if it's newer than destination file
cp Ubuntu_Documents.tar $Backup_Directory
#-----------------------------------------------
cd $SCRIPTS
tar -cvf UM_24_04_Ubuntu_Scripts.tar *.sh *.txt 
cp UM_24_04_Ubuntu_Scripts.tar $Backup_Directory
# 
cp -pv /etc/hosts $Backup_Directory

cp /home/andy/.mozilla/firefox/t0kduppg.default-release/bookmarks.html $Backup_Directory

# show a message showing completion of the script

gxmessage -fg blue -font  'sans 20' -timeout 2 'Computer has been backed up'

Your script does not perform a backup for all the directories for which you defined a path variable:

  • DOCS         [OK]
  • SCRIPTS         [OK]
  • HOME         [MISSING code segment]
  • ICONS         [missing cp command]
  • MY_Sounds         [MISSING code segment]
  • THUNAR         [OK]
  • Music         [MISSING code segment]
  • FedEx         [MISSING code segment]

You might also want to consider replacing the suffix matching strings with regex, namely

*.[Tt][Xx][Tt]
*.[Dd][Oo][Cc]
*.[Rr][Tt][Ff]
*.[Hh][Tt][Mm][Ll]
*.[Pp][Dd][Ff]
*.[Oo][Dd][Tt]
*.[Oo][Dd][Ss]
*.[Oo][Dd][Gg]
*.[Cc][Ss][Vv]
*.[Xx][Ll][Ss]
*.[Jj][Pp][Gg]
*.[Dd][Oo][Cc][Xx]
*.[Oo][Tt][Gg]
*.[Dd][Oo][Cc]

You could use this script to generate those patterns using the command

USER__Find_IndexedFiles.sh --pattern txt doc rtf html png pdf odt ods odg csv xls jpg docx otg doc

to give you the result

	 [Tt][Xx][Tt]
	 [Dd][Oo][Cc]
	 [Rr][Tt][Ff]
	 [Hh][Tt][Mm][Ll]
	 [Pp][Nn][Gg]
	 [Pp][Dd][Ff]
	 [Oo][Dd][Tt]
	 [Oo][Dd][Ss]
	 [Oo][Dd][Gg]
	 [Cc][Ss][Vv]
	 [Xx][Ll][Ss]
	 [Jj][Pp][Gg]
	 [Dd][Oo][Cc][Xx]
	 [Oo][Tt][Gg]
	 [Dd][Oo][Cc]

:slight_smile:

4 Likes

Thanks.

Did you use some kind of script checker?

There were about 3 variable names that were not used.

And one cp command was commented out.

Take care.

3 Likes

I appreciate the feedback, Andy.

All my scripts are deemed "work-in-progress" that are functional but endlessly evolving. I hope it can be of use to you in its current form for the application indicated.

The scripts purpose is much larger, to search for specified string sequences in file names for which I don't know the exact case used.

The outputs from a search on my custom index files looks like this:

8.7M	/DB001_F5/TOPIC__Programming/LANGUAGE__JavaScript/Data Structures and Algorithms with JavaScript.pdf
6.7M	/DB001_F5/TOPIC__Programming/LANGUAGE__JavaScript/Django JavaScript Integration AJAX and jQuery.pdf
1.9M	/DB001_F5/TOPIC__Programming/LANGUAGE__JavaScript/Effective JavaScript.pdf
3.9M	/DB001_F5/TOPIC__Programming/LANGUAGE__JavaScript/Expert JavaScript.pdf
504K	/DB001_F5/TOPIC__Programming/LANGUAGE__JavaScript/HTML5 and JavaScript Web Apps.pdf
12M	/DB001_F5/TOPIC__Programming/LANGUAGE__JavaScript/JavaScript Cookbook.pdf
2.6M	/DB001_F5/TOPIC__Programming/LANGUAGE__JavaScript/JavaScript Creativity.pdf
2.6M	/DB001_F5/TOPIC__Programming/LANGUAGE__JavaScript/JavaScript Security.pdf

... and that is only a very small subset of results for a search on "JavaScript". :slight_smile:

2 Likes

Eric,

You are most welcome.

2 Likes