2 Comments

plasmabac – When plasma solidifys.

Plasma being a new technology for KDE it can still, at times, behave like a bad child. Alot of you may have noticed that plasma from time to time will have the tendency to cause the desktop to freeze or crash. This usually happens with widgets that have bugs in them or if there are errors in the plasma configuration files. Instead of losing all my plasma configurations anytime plasma goes rogue, I’ve made it a routine to back them up regularly. I decided to build a script that can backup the current plasma configs and then automate it to run once a week. The script will both backup and restore:

plasmabac b
plasmabac r

When you choose to restore, it will give you a list of saved plasma configs by date:

plasmabac r
 0) plasmarcs-2009-10-13.tar.gz
 1) plasmarcs-2009-10-18.tar.gz
 2) plasmarcs-2009-10-23.tar.gz
 3) plasmarcs-2009-10-24.tar.gz
 4) plasmarcs-2009-10-25.tar.gz
 5) plasmarcs-2009-10-29.tar.gz
 6) plasmarcs-2009-11-01.tar.gz
 7) plasmarcs-2009-11-02.tar.gz
Choose the plasma configuration to restore: 

To backup on a weekly basis, add it to the cron jobs:

  57  00  *   *   0       ~/.bin/root/backup/plasmabac b    # w - plsm cnfgs
# |   |   |   |   |   user
# |   |   |   |   weekday (0-6) (Sunday=0)
# |   |   |   month (1-12)
# |   |   day (0-31)
# |   hour (0-23)
# minute (0-59)

The script will automaticaly delete configurations older than two months to prevent overflow.

Enjoy :)

#!/bin/bash
# plasmabac - backup and restore local plasma config

backdir=/opt/backup/pc-emach/kde4-plasma-rcs
userdir=/home/gen2ly

# Use filename as program name
prog=${0##*/}

# Text color variables
txtbld=$(tput bold)       # bold
txtund=$(tput sgr 0 1)    # underline
bldblu='\e[1;34m'         # blue
bldred='\e[1;31m'         # red
bldwht='\e[1;37m'         # white
txtrst='\e[0m'            # text reset
info=${bldwht}*${txtrst}
pass=${bldblu}*${txtrst}
warn=${bldred}!${txtrst}

plasmarcs=($(find "$userdir"/.kde4/share/config -type f -name "plasma*"))
bkpplasmarcs=($(find "$backdir" -type f -name "plasma*" | sort))
date=$(date +%F)

# Display usage if full argument isn't given
if [[ -z "$@" ]]; then
  echo " $prog b|r - backup or restore plasma configurations"
  exit
fi

# Check if the directory exists and user has access to it
if [[ -n $(ls "$backdir" 2>&1 | grep denied) ]]; then
  echo -e "$warn User doesn't have access to the backup directory"
  exit
  else
  if [[ ! -d "$backdir" ]]; then
    mkdir "$backdir"
    echo -e "${bldblu}*${txtrst} KDE 4 plasma config backup directory doesn't exist.  Created."
  fi
fi

# Delete backups older than two months
if [[ -n "$(find "$backdir" -mtime +60)" ]]; then
  find "$backdir" -mtime +60 -exec rm {} \;
  echo -e "$pass Configurations older than two months deleted"
fi

case $1 in
  b | backup )  tar -czpf "$backdir"/plasmarcs-"$date".tar.gz ${plasmarcs[@]}
                echo -e "$pass Plasma configurations backed up. (${bldwht}$date${txtrst})"
                ;;
  r | restore ) for((i=0;i<${#bkpplasmarcs[@]};i++)) ; do
                  echo -e " ${txtbld}${i}) ${bkpplasmarcs[$i]##*/}${txtrst}"
                done
                echo -n "Choose the plasma configuration to restore: "
                read restore
                selection="${bkpplasmarcs[$restore]}"
                tar -xvf "$selection" -C /
                echo -e "$pass Restored plasma configs: ${txtbld}${bkpplasmarcs[$restore]##*/}${txtrst}"
                ;;
esac
About these ads

About Gen2ly

<3's linux

2 comments on “plasmabac – When plasma solidifys.

  1. […] immediata e sistematica c’è ed è rappresentata da uno script denominato plasmabac. Lo script si occupa di creare una copia dei files di configurazione di Plasma catalogando le varie […]

  2. It would take hours, if not downright impoossible to continue their weight loss is by eating a
    portion of fresh grapefruit before each meal 7. A
    lot if how youu die pill has been proven scientifically via ORAC rating.
    If you eat mindlessly without taking charge of your calorie and fat intake each and very
    meal for you to maintain a healthy weight and stay fit.

    It may seem counter-intuitive, but eating fat can help you diet pill.

Leave a Reply

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

Follow

Get every new post delivered to your Inbox.

Join 52 other followers

%d bloggers like this: