Tag Archives: linux

Using RSYNC to backup (synchronize) folders

rsync
If you want to synchronize two folders use next snippets.

1. Sync folder “source” content to “target” folder:

rsync -arpv --delete /mnt/source/ /mnt/target

Notice trailing slash for “source” folder!

2. Sync whole folder “source” to “parent” folder:

rsync -arpv --delete /mnt/source /mnt/parent

More info https://linux.die.net/man/1/rsync

Remove kernel in CentOS

kernel
After unsuccessful upgrade of kernel you have to fix linux OS.
To delete invalid kernel in case of CentOS do next steps.

1. Show kernel list:

  rpm -q kernel

And you’ll see output:

  kernel-3.10.0-229.14.1.el7.x86_64
  kernel-3.10.0-229.20.1.el7.x86_64
  kernel-3.10.0-327.3.1.el7.x86_64
  kernel-3.10.0-327.4.4.el7.x86_64
  kernel-3.10.0-327.22.2.el7.x86_64

2. Delete corrupted kernel:

  rpm -e kernel-3.10.0-327.22.2.el7.x86_64

3. Reboot.
So, you system downgraded!

Thanx to http://blog.zwiegnet.com/linux-server/delete-oldcorrupt-linux-kernel-centos/

Backup script for Linux Server in bash

bu
If you are a hardcore linux admin you may use complex backup system like the Bacula or AMANDA or other.
But for simple case it is enough to use bash script. It creates a folder with copied files from filesystem and dumped databases from MySql server. In my case here it is backup.sh:

#!/bin/sh

##--- SETTINGS
ROOT_PATH=$1
DAYS_KEEP=$2

BU_FILES="/etc"
BU_FILES="$BU_FILES;/usr/local/apache2"
BU_FILES="$BU_FILES;/usr/serv/apache/www"

EXCLUDE_PATH_1="/usr/serv/apache/www/stuff"

MYSQL_USER=backuper
MYSQL_PASS='backuper_passwd'

##--- COMMON ENV
DATESTAMP=$(date +%Y-%m-%d)
BU_PATH=${ROOT_PATH}/${DATESTAMP}

##--- BACKUP FILES
FILE_PATH=${BU_PATH}/files
if [ ! -e ${FILE_PATH} ]; then
    mkdir -p ${FILE_PATH}
fi

cd $FILE_PATH

# create backups securely - this will give 660 for new file creation
umask 006

for dir in $(echo $BU_FILES | tr ";" "\n")
do
  printf "Backup dir '${dir}' ... "
  if [ ! -e ${dir} ]; then
    echo "ERROR: Directory not found"
  else
    tar zcfP ${FILE_PATH}/`basename ${dir}`.tar.gz ${dir} --exclude ${EXCLUDE_PATH_1}
    echo "OK"
  fi
done

##--- BACKUP DATABASES
MYSQL_PATH=${BU_PATH}/mysql
if [ ! -e ${MYSQL_PATH} ]; then
    mkdir -p ${MYSQL_PATH}
fi

cd $MYSQL_PATH

# create backups securely - this will give 660 for new file creation
umask 006

# list MySQL databases and dump each one
MYSQL_DB_LIST=`mysql -u $MYSQL_USER -p"$MYSQL_PASS" -e'show databases;'`
MYSQL_DB_LIST=${MYSQL_DB_LIST##Database}
for DB in $MYSQL_DB_LIST;
do
  printf "Backup DB '${DB}' ... "
  mysqldump --single-transaction -u $MYSQL_USER -p"$MYSQL_PASS" --opt --flush-logs --databases $DB | gzip > ${MYSQL_PATH}/${DB}.sql.gz
  echo "OK"
done

# all dbs
printf "Backup all DBs ... "
mysqldump --single-transaction -u $MYSQL_USER -p"$MYSQL_PASS" -A --opt --events --ignore-table=mysql.event --flush-logs | gzip > ${MYSQL_PATH}/all_dbs.sql.gz
echo "OK"

##--- REMOVE backups older than $DAYS_KEEP
find ${ROOT_PATH}/* -mtime +$DAYS_KEEP -exec rm -rf {} \; 2> /dev/null

cd /var

The example usage:

  ./backup.sh /var/backups 30

where:
/var/backups – path to dir where backup will be placed;
30 – days count of backups to save;

You can download all files: backup_scripts

Create desktop application launcher in Linux

app-launcher
To create a launcher for your downloaded new software you can do following:
1. Create file “YourAppName.desktop” in ~/Desktop folder.
2. Fill it with params:

[Desktop Entry]
Name=YourAppName
Exec=~/apps/YourAppName/bin/run.sh
Icon=~/apps/YourAppName/bin/icon.png
Type=Application
Terminal=false
StartupNotify=true

This is workaround for “Do you want to run or display its contents?” dialog message!

For more examples see /usr/share/applications folder.

Keyboard layout configuration with setxkbmap in Linux

dvorak2

To get worked keyboard layout well follow next steps:

1. Install x11-xkb-utils package:

# apt-get install x11-xkb-utils

2. Add the line to your ~/.xinitrc file:

setxkbmap -layout 'us,ru' -option 'grp:ctrl_shift_toggle'

Help with grp:

  • grp: toggle – switch right Alt;
  • grp: shift_toggle – two keys shift;
  • grp: ctrl_shift_toggle – ctrl shift;
  • grp: alt_shift_toggle – alt shift;
  • grp: ctrl_alt_toggle – ctrl alt;
  • grp: caps_toggle – switching on CapsLock;
  • grp: lwin_toggle – switch on the left “Win” key on a Windows keyboard ( for the X Window older than 4.2) ;
  • grp: rwin_toggle – switching from the right “Win” key on a Windows keyboard ( for the X Window older than 4.2) ;
  • grp: menu_toggle – switching on the ” Context Menu ” on the Windows keyboard ( for the X Window older than 4.2) ;
  • grp: lctrl_toggle – switch on the left Control key
  • grp: rctrl_toggle – switching from the right Control key
  • grp: switch – switch on the right Alt only at the time of pressing
  • grp: lwin_switch – switch on the left Windows key only at the moment of pressing
  • grp: rwin_switch – switch on the right key Windows only at the moment of pressing
  • grp: win_switch – switching on any key Windows only at the moment of pressing

So simple, good luck!

See also,
http://linuxru.org/tips/41
http://ubuntologia.ru/forum/viewtopic.php?f=34&t=4245&start=10

Install Pantheon shell on Ubuntu Linux

pantheonshell
Today i’am going to show you how to install great minimalistic and beautiful Linux shell named Pantheon on Ubuntu.

First of all, install Ubuntu minimal from https://help.ubuntu.com/community/Installation/MinimalCD

After that, see below.

1. Install util for repositories managing:

apt-get install python-software-properties
 

2. Install Pantheon shell:

apt-add-repository -y ppa:elementary-os/stable
apt-get update
apt-get install elementary-desktop
 

3. Check installed gala and switchboard packets:

apt-get install gala
apt-get install switchboard-plug-pantheon-shell
 

4. Install Pantheon tweaks:

apt-add-repository ppa:versable/elementary-update
apt-get update
apt-get install elementary-tweaks
 

5. Reboot.

And you’ll got this:
9468089

See also http://www.binarytides.com/install-pantheon-ubuntu/
Here is txt file for VirtualBox installation: pantheon install

Chroot howto in Linux

chroot

To get chroot in linux do the following:

  sudo chroot /mounted/directory
  mount proc
  mount sys
  mount dev

After that you can easily update grub, etc.
Thanx to http://askubuntu.com/questions/110911/how-can-i-run-update-grub-on-a-chroot-filesystem