nav-left cat-right
cat-right
Matthias Pospiech > Linux > Restore some configuration files

Restore some configuration files

Sometimes I do not want to reuse my old $HOME/.kde folder completely or other hidden folders after I reinstalled the operating system. In this case I want to copy only selected folders and file to the new $HOME. This script does most of the necessary copy operations for me: CopyConfigFiles.script
#!/bin/bash
 
# --------------------------------------------------------- #
copy_and_backup_Files ()
{
	COPY=$3
	FROMDIR="$1"
	DESTDIR="$2"
	if [ -d "$FROMDIR/$COPY" ]  # Test if origin directory exists.
	then
		if [ -d "$DESTDIR/$COPY" ]  # Test if target directory exists.
		then
			if [ -d "$DESTDIR/$COPY-old" ]  # Test if target directory exists.
			then
				rm -rf "$DESTDIR/$COPY-old" 
			fi		
			mv "$DESTDIR/$COPY" "$DESTDIR/$COPY-old"
			cp -rv "$FROMDIR/$COPY" "$DESTDIR"
		else
			echo "> Kopieren..."			
			cp -rv "$FROMDIR/$COPY" "$DESTDIR"
		fi
	fi
	return 0   # Success.
}  
# --------------------------------------------------------- #
copy_and_backup_File ()
{
	COPY=$3
	FROMDIR="$1"
	DESTDIR="$2"
	if [ -e "$FROMDIR/$COPY" ]  # Test if origin directory exists.
	then
		if [ -e "$DESTDIR/$COPY" ]  # Test if target directory exists.
		then
			if [ -e "$DESTDIR/$COPY-old" ]  # Test if target directory exists.
			then
				rm "$DESTDIR/$COPY-old" 
			fi		
			mv "$DESTDIR/$COPY" "$DESTDIR/$COPY-old"
			cp -v "$FROMDIR/$COPY" "$DESTDIR"
		else
			echo "> Kopieren..."			
			cp -v "$FROMDIR/$COPY" "$DESTDIR"
		fi
	fi
	return 0   # Success.
}  
 
echo "-----------------------------------"
 
OLDHOME="/home/matthias-old"
NEWHOME="/home/matthias"
 
COPY=".spamassassin"
copy_and_backup_Files "$OLDHOME" "$NEWHOME" $COPY
 
COPY="kmail"
CPATH=".kde/share/apps"
copy_and_backup_Files "$OLDHOME/$CPATH" "$NEWHOME/$CPATH" $COPY
 
 
CPATH=".kde/share/apps"
COPYDIR=(kwallet kontact kile kabc kaddressbook knode kopete korganizer)
for DIR in "${COPYDIR[@]}"
do
	copy_and_backup_Files "$OLDHOME/$CPATH" "$NEWHOME/$CPATH" $DIR
done
 
CPATH=".kde/share/config"
COPYFILE=(akregatorrc amarokrc digikamrc emaildefaults emailidentities kab2kabcrc kaccessrc kaddressbook_addrconfig kaddressbookrc katerc kateschemarc katesyntaxhighlightingrc kilerc kmail.eventsrc kmailrc knoderc kopeterc korganizerrc kwalletrc rsibreakrc)
 
for COPY in "${COPYFILE[@]}"
do
	copy_and_backup_File "$OLDHOME/$CPATH" "$NEWHOME/$CPATH" $COPY
done

Einen Kommentar schreiben

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.

*

This blog is kept spam free by WP-SpamFree.