Friday, October 26, 2012

Rsync Backup Script.

This script can keep history of last 3 backups.

Source Link
http://michaeldadams.org/projects/backup/backup


#!/bin/sh

## Copyright (c) 2010-2011, Michael D. Adams
## 
## 
## Permission to use, copy, modify, and/or distribute this software for any
## purpose with or without fee is hereby granted, provided that the above
## copyright notice and this permission notice appear in all copies.
## 
## THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
## WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
## MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
## ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
## WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
## ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
## OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

set -u # Variables that are not set are errors
set -x # Print commands when executed

HOST=user@host.com
SRC=/path/to/src # no slash at end
DST=/path/to/dst # no slash at end

# If backup.0 already exists then bump age numbers and remove old backup.3
if ssh "$HOST" test -d "$DST"/backup.0; then
    ssh "$HOST" rm -rf "$DST"/backup.3
    ssh "$HOST" mv "$DST"/backup.2 "$DST"/backup.3
    ssh "$HOST" mv "$DST"/backup.1 "$DST"/backup.2
    ssh "$HOST" mv "$DST"/backup.0 "$DST"/backup.1
fi

# --progress: so we know if the program froze
# --archive:
#     recursive, links, permissions, times, group, owner, devices, specials
# --delete: remove no longer existant files in old backup.pre.
#     We don't delete the entire old backup.pre so we can do a fast restart.
# -F: use per-directory ".rync-filter" files to filter
# --rsh: tunnel over SSH
# --link-dest: share hard links to unchanged files with previous backup
rsync --progress --archive --delete -F --rsh=ssh --link-dest=../backup.1 \
  "$SRC" "$HOST":"$DST"/backup.pre &&
ssh "$HOST" mv "$DST"/backup.pre "$DST"/backup.0

Sunday, October 7, 2012

Linux Creating a Partition Size Larger Than 2TB

Creates a new GPT disklabel i.e. partition table:
(parted) mklabel gpt
Sample outputs:
Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? yes
(parted)
Next, set the default unit to TB, enter:
(parted) unit TB
To create a 3TB partition size, enter:
(parted) mkpart primary 0 2
 
 
 
 (parted) mkpart primary 2 3
 
 
 
 
*** In case you need a single partition of 3TB 
(parted) mkpart primary 0 0
 
 
To print the current partitions, enter:
(parted) printSample outputs:
Model: ATA ST33000651AS (scsi) Disk /dev/sdb: 3.00TB Sector size (logical/physical): 512B/512B Partition Table: gpt Number Start End Size File system Name Flags 1 0.00TB 3.00TB 3.00TB ext4 primaryQuit and save the changes, enter:
(parted) quit
  

Friday, October 5, 2012

sftp chroot selinux centos 6.2 - tested working

If yo want to configure secure FTP server where user cannot get out of there home directories (ie chroot environment). Please follow below steps to achieve this.

Steps for setting sftp with chroot on centos 6.

We have to create a sftpgroup first and add these users to be part of this group. All these users will be part of sftpgroup.


cp -p /etc/ssh/sshd_config /etc/ssh/sshd_config-original

vim /etc/ssh/sshd_config

*** Comment out line ---
Subsystem      sftp    /usr/libexec/openssh/sftp-server

Add these lines --- considering group name will be sftpgroup and users home directories as /home


Subsystem sftp internal-sftp

Match Group sftpgroup

ChrootDirectory /home/%u
X11Forwarding no
AllowTcpForwarding no
ForceCommand internal-sftp

-------

groupadd sftpgroup

/etc/init.d/sshd restart

useradd -g sftpgroup -s /sbin/false amit

mkdir /home/amit/upload

chown root:root /home/amit

chmod 755 /home/amit

chown amit:sftpgroup /home/amit/upload

if you are running SE LINUX , you need give below command for all this to work.


setsebool -P ssh_chroot_rw_homedirs on


If you want user upload should go on storage below option on solve this issue.

Where /storage/home/amit is on storage box.
and /home/amit is will be a mount point.

mount -o bind /storage/home/amit /home/amit

----------------

Some part of this is learned from

http://bachradsusi.livejournal.com/2239.html