Little Girl's Mostly Linux Blog

MySystemFiles

The mysystemfiles script

This page was last updated on September 29, 2013.

Table Of Contents

  • About the script
  • See the script
  • Get the script
  • Use the script
  • Obligatory Happy Ending
  • About the script

    This is a simple Bash script that backs up 14 of your Kubuntu 12.04 Precise Pangolin system files to a directory on your Desktop and lets you know what it’s doing while it runs. The files it backs up are:

    • ~/.bashrc
    • /boot/grub/grub.cfg
    • /etc/apt/sources.list
    • /etc/aliases
    • /etc/crontab
    • /etc/default/nfs-common
    • /etc/default/nfs-kernel-server
    • /etc/exports
    • /etc/fstab
    • /etc/hosts.allow
    • /etc/hosts.deny
    • /etc/idmapd.conf
    • /etc/network/interfaces
    • /etc/X11/xorg.conf

    See the script

    #!/bin/bash
    ################################################################################
    # STEP_1 - ABOUT THIS SCRIPT                                                   #
    ################################################################################
    STEP_1() {
    	echo "#################################################################"
    	echo "#   mysystemfiles v0.6                                          #"
    	echo "#                                                               #"
    	echo "#   by Little Girl                                              #"
    	echo "#   https://mostlylinux.wordpress.com                            #"
    	echo "#                                                               #"
    	echo "#   Anyone may feel free to use and/or modify this script.      #"
    	echo "#                                                               #"
    	echo "#   This script copies 14 of your system files.                 #"
    	echo "#                                                               #"
    	echo "#   The copied files will be placed on your Desktop in a        #"
    	echo "#   directory named MySystemReports and will have the current   #"
    	echo "#   date added to their names.                                  #"
    	echo "#################################################################"
    	echo
    	}
    ################################################################################
    # STEP_2 - HELP SECTION                                                        #
    ################################################################################
    STEP_2() {
    	echo "#################################################################"
    	echo "#    HOW TO USE THIS SCRIPT IN A TERMINAL:                      #"
    	echo "#                                                               #"
    	echo "# 1. Open a terminal window.                                    #"
    	echo "#                                                               #"
    	echo "# 2. Change to the directory this script is in. For example:    #"
    	echo "#                                                               #"
    	echo "#                       cd /home/Desktop                        #"
    	echo "#                                                               #"
    	echo "# 3. Type this command:                                         #"
    	echo "#                                                               #"
    	echo "#                   bash mysystemfiles.bash                     #"
    	echo "#                                                               #"
    	echo "#    HOW TO USE THIS SCRIPT FROM A SHORTCUT:                    #"
    	echo "#                                                               #"
    	echo "# 1. Right-click this script in your file manager. Change its   #"
    	echo "#    properties so that it's executable and runs in a terminal. #"
    	echo "#                                                               #"
    	echo "# 2. Create a shortcut to the script and place the shortcut     #"
    	echo "#    anywhere you like.                                         #"
    	echo "#                                                               #"
    	echo "# 3. Use the shortcut to run the script.                        #"
    	echo "#################################################################"
    	echo
    	exit
    	}
    ################################################################################
    # STEP_3 - CHECK FOR DESTINATION DIRECTORY. CREATE IT IF NECESSARY.            #
    ################################################################################
    STEP_3() {
    	echo "Checking if MySystemFiles directory exists on the Desktop..."
    	if
    		[ -d ~/Desktop/MySystemFiles ];
    	then
    		echo "MySystemFiles directory exists. Continuing...";
    	else
    		echo "Creating MySystemFiles directory...";
    		mkdir ~/Desktop/MySystemFiles;
    	fi;
    	}
    ################################################################################
    # STEP_4 - COPY SYSTEM FILES TO DESTINATION DIRECTORY                          #
    ################################################################################
    STEP_4() {
    	echo "Copying the files...";
    	LIST_OF_FILES=(
    			"/home/$USER/.bashrc"
    			"/boot/grub/grub.cfg"
    			"/etc/apt/sources.list"
    			"/etc/aliases"
    			"/etc/crontab"
    			"/etc/default/nfs-common"
    			"/etc/default/nfs-kernel-server"
    			"/etc/exports"
    			"/etc/fstab"
    			"/etc/hosts.allow"
    			"/etc/hosts.deny"
    			"/etc/idmapd.conf"
    			"/etc/network/interfaces"
    			"/etc/X11/xorg.conf"
    			);
    	for item in "${LIST_OF_FILES[@]}";
    	do
    		cp $item ~/Desktop/MySystemFiles/$(basename $item)--$(date +%Y-%m-%d);
    	done;
    	}
    ################################################################################
    # STEP_5 - DISPLAY JOB DONE AND PROMPT USER TO CLOSE THE WINDOW                #
    ################################################################################
    STEP_5() {
    	echo -n "Done! Press the Enter key to exit this script.";
    	read keypress;
    	}
    ################################################################################
    # STEP_6 - BEGIN THE SCRIPT                                                    #
    ################################################################################
    ################################################
    # IF NO OPTIONS ARE USED RUN THESE STEPS       #
    ################################################
    if
    	[ $# = '0' ];
    then
    	STEP_1 | more;
    	STEP_3;
    	STEP_4;
    	STEP_5;
    ################################################
    # IF ONE OPTION IS USED RUN ONE OF THESE STEPS #
    ################################################
    elif
    	[ $# = '1' ];
    then
    	########################################
    	# IF KNOWN OPTION RUN THIS STEP        #
    	########################################
    	if [ "$1" = "-h" ];
    	then
    		STEP_2 | more;
    	########################################
    	# IF KNOWN OPTION RUN THIS STEP        #
    	########################################
    	elif
    		[ "$1" = "--help" ];
    	then
    		STEP_2 | more;
    	########################################
    	# IF UNKNOWN OPTION DO THIS            #
    	########################################
    	else
    		echo "invalid option";
    	fi
    ################################################
    # IF MORE THAN ONE OPTION IS USED DO THIS      #
    ################################################
    else
    	echo "invalid number of options";
    fi
    

    Get the script

    Get the script in one of these ways:

    • Download mysystemfiles_v0.6.zip from Box.
    • Download mysystemfiles_v0.6.zip from Host-A.
    • Get the script manually:

      1. Copy the script above.
      2. Paste the copied script into a text editor.
      3. Save it as mysystemfiles.bash somewhere on your computer.

    Use the script

    1. Open a terminal window.
    2. Change to the directory the script is in. For example, if the script is on the Desktop, you would type this command:
      cd ~/Desktop
    3. Press the Enter key.
    4. Run the script by typing this command:
      bash mysystemfiles.bash
    5. Press the Enter key.
    6. Type in your password when asked.
    7. When the script finishes running, press the Enter key and close the terminal window.
    8. Copies of the files will be in the MySystemFiles directory on your Desktop. You can move the directory to another location on your computer or keep it on your Desktop.

    Obligatory Happy Ending

    And they all lived happily ever after. The end.

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Comment:

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: