Files/Directories to backup to a 2nd drive

I use this to backup important files to a second drive.

I forgot where I saw it, but some people backup /home/johndoe

If I did back that up, would that help me if I had to reinstall my operating system?

I use Ubuntu.

 #!/bin/bash
 #
 #  BACKUP IMPORTANT FILES TO MAXTOR DRIVE
 #
 # Don't use ALLCAPS for variable names or begin them with a number.
 #

 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
 /usr/bin/rsync --progress -r -u Thunar_Custom_Actions.tar $Backup_Directory
 #--------------------------------
 cd /home/andy/Dog_Attack/
 tar -cf Dog_Attack_Documentation.tar *.png *.pdf *.odt *.jpg *.mp4
 /usr/bin/rsync --progress -r -u Dog_Attack_Documentation.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
 ## ONLY copy file if it's newer than destination file
 ##
 /usr/bin/rsync --progress -r -u Ubuntu_Documents.tar $Backup_Directory

 #-----------------------------------------------
 cd $SCRIPTS
 tar -cvf UM_24_04_Ubuntu_Scripts.tar *.sh *.txt
 /usr/bin/rsync --progress -r -u UM_24_04_Ubuntu_Scripts.tar $Backup_Directory
 #
 # Backup Firefox bookmarks.
 #
 # Backup my music
 /usr/bin/rsync --progress -r -u /home/andy/.mozilla/firefox/t0kduppg.default-release/bookmarks.html $Backup_Directory
 #
 cd $Music
 tar -cvf My_Music.tar *.mp3
 /usr/bin/rsync --progress -r -u My_Music.tar $Backup_Directory
 #
 cd $FedEx
 tar -cvf FedEx_Documentation.tar *.png $Backup_Directory
 /usr/bin/rsync --progress -r -u FedEx_Documentation.tar $Backup_Directory
 #
 #date +'%m/%d/%Y %I:%M:%S %p' > /home/andy/Downloads/Computer_Backup.txt
 gxmessage -fg blue -font  'sans 20' -timeout 2 'Computer has been backed up'

Welcome!

Please put your code between ``` lines (code block markdown)!

You add the full $Backup_Directory contents to the FedEx_Documentation.tar ??
I think you want to only tar the *.png files.

How about a smart loop?

#!/bin/bash
 #
 #  BACKUP IMPORTANT FILES TO MAXTOR DRIVE
 #
 # Don't use ALLCAPS for variable names or begin them with a number.
 #

PATH=/usr/bin:/bin:/usr/sbin:/sbin

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

# fromdir  tarfile  filenames
echo "
# THUNAR
/home/andy/.config/Thunar/  Thunar_Custom_Actions.tar  uca.xml

# DOG_ATTACKS
/home/andy/Dog_Attack/  Dog_Attack_Documentation.tar  *.png *.pdf *.odt *.jpg *.mp4

# DOCS
/home/andy/Documents/  Ubuntu_Documents.tar  *.txt *.doc *.rtf *.html *.png *.pdf *.odt *.ods *.odg *.csv *.xls *.jpg *.PDF *.docx *.otg

# SCRIPTS
/home/andy/bin/  UM_24_04_Ubuntu_Scripts.tar  *.sh *.txt

# Firefox bookmarks
-  -  /home/andy/.mozilla/firefox/t0kduppg.default-release/bookmarks.html

# Music
/home/andy/Music/  My_Music.tar  *.mp3

# FedEx
/home/andy/FedEx/  FedEx_Documentation.tar  *.png

# ICONS
/home/andy/Icons/  Icons.tar  *

# MY_Sounds
/usr/share/sounds/My_Sounds/  My_Sounds.tar  *

" |
while read fromdir tarfile filenames
do
  # Skip #comment lines and empty lines
  case "$fromdir" in ( "#"* | "" )
    continue
  esac
  # cd if not "-"
  if [ "$fromdir" != "-"  ]; then
    cd "$fromdir" || continue
  fi
  # tar if not "-"
  if [ "$tarfile" != "-" ]; then
    tar -cf "$tarfile" $filenames
  else
    # otherwise rsync file(s) directly
    tarfile=$filenames
  fi
  rsync --progress -r -u $tarfile "$Backup_Directory"
done

#date +'%m/%d/%Y %I:%M:%S %p' > /home/andy/Downloads/Computer_Backup.txt
gxmessage -fg blue -font  'sans 20' -timeout 2 'Computer has been backed up'
1 Like