Labels
amazon
apache
apt
aptitude
automate docker image
awk
aws
awstat
backup
bandwidth
bash
binary log
bond
bridge
caching
centos
centos 7
cluster
concurrency
csv
digitalocean
disk
django
docker
docker images
dovecot
drop cache
enviroment
error
explain
free
fstab
ftp
git
gluster
go
gpg
grep
grub
header
header check
icinga2
imapsync
information
innodb
ip
iproute
isolation
ispconfig
java
jenkins
jump
kdump
keepalived
kvm
linux
locale
logbuffer
lookbehind
macos
mail
maillog
matplotlib
mcrypt
memory
modrewrite
monitoring
mount
msyql ndbcluster
mta
multipath
mutt
my.cnf
mysql
mysql error
mysql optimization
mysql permission
mysqlcluster
mysqldump
nethogs
network
nginx
node
nopasswd
ntp
nxlog
openssl
optimization
parsing
parted
password
pflogsumm
php
php-fpm
php5-mcrypt
phpmyadmin
pip
policyd
post
postfix
proxy
pycurl
python
query_cache
querydict
rdesktop
rds
recommender systems
recover mysql
redhat
redolog
regex
regularexpression
resilver
roundcube
route
rsync
scrapy
script
scrub
security
service
setfacl
sftp
slow
smtp
snnp
spamassassin
spotlight
sql
squirrelmail
ssc
ssh
ssh-copy-id
ssl
startup
syslog
syslog over tls
tar
telnet
tls
tomcat
transaction
troubleshoot
tuning
ubuntu
udev
ulimit
usb
vdev removal
virtualhost
virtualization
virtualmin
vrrp
watch
webscrape
wget
x11
zfs
zfs send
zfs recv
zpool
Setup a proxy server with web content filtering: squid+rejik+squint+sqstat
This summary is not available. Please
click here to view the post.
Linux Network Load Balancer For Multiple ISP Links
This article explains how to configure a Redhat/CentOS (and many
other Linux distributions) Linux server as a load balancer. For this
example, there are two routers each with a different ISP although they
could be the same ISP.
This was tested on a CentOS 6.3 64bit server.
In the script below, the load balancer has three interfaces: Eth0 is on the inside while Eth1 and Eth2 are connected to the routers.
Server addresses:
Eth0 = 192.168.0.10 (connected to inside network)
Eth1 = 192.168.1.10 (connected to router1/ISP1)
Eth2 = 192.168.2.10 (connected to router2/ISP2)
Router addresses:
Router1 = 192.168.1.1
Router2 = 192.168.2.1
Create a script file called “/usr/bin/lb.sh” with the following contents:
Add the following to the end of the “/etc/iproute2/rt_tables” file:
Make sure to configure static routes on the routers so they know their way back to the inside network.
From >>>
http://agix.com.au/blog/?p=3173
This was tested on a CentOS 6.3 64bit server.
In the script below, the load balancer has three interfaces: Eth0 is on the inside while Eth1 and Eth2 are connected to the routers.
Server addresses:
Eth0 = 192.168.0.10 (connected to inside network)
Eth1 = 192.168.1.10 (connected to router1/ISP1)
Eth2 = 192.168.2.10 (connected to router2/ISP2)
Router addresses:
Router1 = 192.168.1.1
Router2 = 192.168.2.1
Create a script file called “/usr/bin/lb.sh” with the following contents:
#!/bin/bash # By Andrew Galdes, AGIX, 4 April 2013 # Remember to turn off (or customise) SELinux and add the ROUTER1/2 in # the "/etc/iproute2/rt_tables" file. # Do NAT on this server. service network restart ip route flush cache ip route add 192.168.1.0/24 dev eth2 src 192.168.1.10 table ROUTER1 ip route add default via 192.168.1.1 table ROUTER1 ip route add 192.168.2.0/24 dev eth1 src 192.168.2.10 table ROUTER2 ip route add default via 192.168.2.1 table ROUTER2 ip rule add from 192.168.1.10 table ROUTER1 ip rule add from 192.168.2.10 table ROUTER2 # the following command is one line: ip route append default scope global nexthop via 192.168.1.1 dev eth1 weight 1 nexthop via 192.168.2.1 dev eth2 weight 1 route del default gw 192.168.1.1 route del default gw 192.168.2.1 ip routeMake the script executable:
chmod 755 /usr/bin/lb.shAdd the script to the boot process:
vi /etc/rc.localUse the following command to make sure the firewall is set correct.
system-configure-firewallThe firewall should trust the Eth+ devices. It should masquerade the Eth+ devices.
Add the following to the end of the “/etc/iproute2/rt_tables” file:
1 ROUTER1 2 ROUTER2Consider turning off SELinux as follows or make considered changes:
setenforce 0Set it permanently in the “/etc/sysconfig/selinux” file if you like.
Make sure to configure static routes on the routers so they know their way back to the inside network.
From >>>
http://agix.com.au/blog/?p=3173
Rsnapshot linux
Rsnapshot
Why are backups important? Well, hardware failures, accidental file deletion(s), files become corrupted, etc.. Backups can help recover data where applications are being updated/upgraded. Enough reasons?
Where should backups be stored? Due to the inevitable failure of hardware it is desirable to store backups on a separate system from where the production data is stored. Or possibly to an external medium such as an external USB disk drive. This article discusses backing up to an external USB drive.
Please Note:
rnapshot depends on attributes that are unique to Linux/Unix (i.e. ext3, ext4) filesystems only. If backups to "CIFS" (Samba a.k.a. smb, fat, fat32, vfat, ntfs) filesystems are required a different backup application must be used (i.e. rdiff-backup).
| Here is a good book that discusses backups, recoveries, rsnapshot and rdiff-backup: "Backup & Recovery: Inexpensive Backup Solutions for Open Systems, by W. Curtis Preston". |
Contents |
Preparing an External USB Drive
Off-the-shelf external USB drives normally are setup to work with computers that utilize CIFS type filesystems. rsnapshot uses a "hard links" feature that is unique to Linux/Unix filesystems (ext3). "Hard Links" are not supported on filesystems such as: "smbfs", "Samba (SMB)", "FAT", "FAT32", "NTFS", "CIFS", "vfat". Please note that "Amahi Greyhole" mounts Amahi shares that will look like "local disk drives" but these are Samba (SMB) mounted shares. An external disk drive will have to be prepared for a Linux/Unix filesystem, in particular ext3. Why? ext3 has been around for sometime, is stable, and "Windows" computers have Open Source drivers available that can be installed to gain access to an ext3 drive.Prepare an external drive for ext3 as follows:
- The external USB drive used in this example is a 1 Terabyte (1 TB) Seagate drive.
- Plug the drive in to a USB connector and power it up.
- Using a "terminal" session, login in using the "root" user ID.
- The "device name" of the drive needs to be determined.
Enter the following command:
bash code dmesg
The following information is displayed:
Text [11122.304178] usb 2-4: new high-speed USB device number 5 using ehci_hcd
[11122.422152] usb 2-4: New USB device found, idVendor=0bc2, idProduct=3320
[11122.422165] usb 2-4: New USB device strings: Mfr=2, Product=3, SerialNumber=1
[11122.422173] usb 2-4: Product: Expansion Desk
[11122.422180] usb 2-4: Manufacturer: Seagate
.
.
.
.
.
[11123.516813] sdb: sdb1
- The "device name" is "sdb1".
- The USB drive needs to be "unmounted".
bash code umount /dev/sdb1
- Format drive for ext3 filesystem and set drive label name as "usbdisk".
bash code mkfs -t ext3 -v -L usbdisk /dev/sdb1
- Please Note: THIS WILL ERASE ALL DATA ON /dev/sdb1, MAKE SURE THIS IS THE CORRECT USB DRIVE AND NOT ANOTHER DRIVE.
The following information is displayed:
Text mke2fs 1.42.5 (29-Jul-2012)
fs_types for mke2fs.conf resolution: 'ext3'
Filesystem label=usbdisk
OS type: Linux
.
.
.
.
.
Writing superblocks and filesystem accounting information: done
- Whenever a drive is formatted in Linux, about 5% is reserved of the total space on the drive for the operating system to continue using the hard drive to operate, even if it gets full. This is totally unnecessary for a USB external hard drive if it stores only data and not to run an operating system.
Enter the following to remove the reserved space:
bash code tune2fs -m 0 /dev/sdb1
The following information is displayed:
Text tune2fs 1.42.5 (29-Jul-2012)
Setting reserved blocks percentage to 0% (0 blocks)
- The external drive is now ready for use.
Mounting an External USB Drive
There are two methods of mounting an external USB drive. The first, mounts the drive automatically each time the server "boots" or "reboots". The second, is mounted manually by the "root" user via the "command-line".
Before proceeding a couple of information items need to be gathered:
- In the previous section the device name found found via the "dmesg" command. The device name found was "sdb1".
- We set the set the external drive's "label". It was set to "usbdisk".
To find the label at anytime via the "root" user ID enter:
bash code e2label /dev/sdb1 The following information is displayed:Both methods of mounting will be controlled by the server's "fstab" configuration file. The fstab (a.k.a. file systems table) file is a system configuration file containing lists of available disks and disk partitions, and indicates how they are to be initialized or otherwise integrated into a system's file system. When the "mount" command is used, the fstab file is read to determine which options should be used when mounting a specified device.
Text usbdisk
Auto-Mounting
Auto-mount of an external USB drive will occur when a server "boots" or "reboots". Provided the fstab configuration file is properly configured. A powered up USB drive that is plugged in after a server has completed the boot process is not auto-mounted. However, using a "terminal" session with the "root" user ID, and issuing a "mount -a" command will mount an external USB drive.
Configure fstab to auto-mount an external USB drive do the following:
- Start a "terminal" session login to the "root" user ID.
- Navigate to the "etc" directory with the "cd" command and make a backup of the current fstab file.
bash code cd /etc
cp /fstab /fstab_bak
- Using a preferred file editor (i.e. vi, nano), open the fstab file.
bash code nano fstab
- Near the bottom of the and after the other fstab entries, add the following:
Text LABEL=usbdisk /media/usbdisk ext3 defaults 0 0
- Now save the fstab file and exit the editor.
- Navigate to the /media directory and create a "usbdisk" directory. This is where the external drive will be mounted, this is called a "mount point".
bash code cd /media
mkdir usbdisk
- Make sure the external drive USB cable is connected to the server and is powered up.
- Reboot the server.
- Remember the disk label set earlier when formatting the drive? During the boot process when the "LABEL" is read, this instructs the system to find a hard disk with the label "usbdrive", and then mounts it to the mount point, "/media/usbdisk".
Manual Mounting
Mount of an external USB drive will not occur when a server "boots" or "reboots" when the fstab configuration file is configured for manual mounting. A powered up USB drive that is plugged in after a server has completed the boot process is also not mounted.
Configure fstab for a manual mounting of an external USB drive with the following:
- Start a "terminal" session login as the "root" user ID.
- Navigate to the "etc" directory with the "cd" command and make a backup of the current fstab file.
bash code cd /etc
cp /fstab /fstab_bak
- Using a preferred file editor (i.e. vi, nano), open the fstab file.
bash code nano fstab
- Near the bottom of the and after the other fstab entries, add the following:
Text LABEL=usbdisk /media/usbdrive ext3 rw,noauto,users,exec,noatime 0 0
- Now save the fstab file and exit the editor.
- Navigate to the /media directory and create a "usbdisk" directory. This is where the external drive will be mounted, this is called a "mount point".
bash code cd /media
mkdir usbdrive
- Make sure the external drive USB cable is connected to the server and is powered up.
- Reboot the server.
- Start a "terminal" session login as the "root" user ID.
- To manually mount the external drive issue the following command:
bash code mount -L usbdisk
- The system reads the fstab, when it finds a line entry with the label "usbdrive", it mounts the drive the mount point, "/media/usbdisk".
Unmounting
With both mounting methods the external drive can be unmounted by the following:
- Start a "terminal" session login as the "root" user ID.
- Issue the following command to unmount the external drive:
bash code umount /media/usbdrive
- Should an error occur indicating that the drive is busy and cannot be unmounted enter the command below. Then try the unmount command again.
bash code fuser -km /media Installing rsnapshot
rsnapshot is available as a package in both the Fedora and Ubuntu Linux distributions. The installation shown here is based on Fedora.
- Open a "terminal" session and login using the "root" user ID:
bash code yum install rsnapshot
- Now create the directory structures for storing the backups:
bash code mkdir -p /media/usbdisk/.private/.snapshots
chmod 0700 /media/usbdisk/.private/
chmod 0755 /media/usbdisk/.private/.snapshots/
Configuring rsnapshot
This section shows how to configure the rsnapshot.conf configuration file.
- Open a "terminal" session and login to the "root" user ID.
- Move to the "/etc" directory.
bash code cd /etc
- Make a backup copy of the rsnapshot configuration file. Why? So that there is a reference just in case.
bash code cp rsnapshot.conf rsnapshot.conf.bkup
- Now using a favourite editor, open the "rnapshot.conf" file.
Please Note: Items in the configuration file are separated by "tab" characters and NOT multiple spaces.
bash code nano rsnapshot.conf
- Find the "SNAPSHOT ROOT DIRECTORY" section and change "snapshot_root" to path where the backups will be stored.
Text snapshot_root /media/usbdisk/.private/.snapshots/
- Find the "no_create_root" section and remove the "#". This will allow rsnapshot to create the "snapshot root" directory.
Text no_create_root 1
- Find the "BACKUP INTERVALS" section and change the line items. What does this all mean? The "#" character at the beginning of each line means the configuration line item will not be enabled. Remove the "#" character as required. For example, when enabled the "interval daily" line will be active and 7 days of backups will be kept.
Text interval hourly 6
interval daily 7
interval weekly 4
interval monthly 12
- Find the "GLOBAL OPTIONS" section. This section defines how much information will be saved in the rsnapshot "log" file.
The options are: Verbose level, 1 through 5. 1 Quiet Print fatal errors only 2 Default Print errors and warnings only 3 Verbose Show equivalent shell commands being executed 4 Extra Verbose Show extra verbose information 5 Debug mode EverythingChange the following options as required:
Text verbose 3
loglevel 3
- Find the "logfile" line and change the line item. After rsnapshot has completed backups this is where the resulting "log" file is stored. Change this line as required.
Text logfile /var/log/rsnapshot
- Find the "BACKUP POINTS / SCRIPTS" section. Add changes as seen below. This is the section that defines the "key directories" that will be backed up. Please note the "localhost/", this represents the server that it being backed up. "localhost/" is a default name given to the current server. Change this name as required, say "amahiBox/"?
Text backup /var/hda/files/docs/ localhost/
backup /var/hda/files/pictures/ localhost/
backup /var/hda/files/movies/ localhost/
backup /var/hda/files/music/ localhost/
backup /var/hda/files/other_shares_you_made localhost/
- Save the "rsnapshot.conf" file.
Test the Configuration Changes
- Now the changes to the rsnapshot configuration file have to be tested. rsnapshot has a feature to test changes to make sure things have been setup correctly.
- Enter the following on the command-line to initiate the test.
bash code rsnapshot configtest
- When the test completes the following should be displayed:
Text Syntax OK
- If an error occurs the rsnapshot configuration file will need to be checked.
Automate Backups
Backups can be automated by creating a "cron job" that can be executed by the system at predetermined intervals.
- Using a "terminal" session and "root" user ID a "cron job" configuration can be created to perform automated backups.
Create a "cronjobs" text file as follows:
bash code crontab -l > cronjobs
- Using a favourite text editor open the cronjobs file.
bash code nano cronjobs
- Add to the cronjobs file for rsnapshot:
Text 0 */4 * * * /usr/bin/rsnapshot hourly
30 23 * * * /usr/bin/rsnapshot daily
00 23 * * 1 /usr/bin/rsnapshot weekly
30 22 1 * * /usr/bin/rsnapshot monthly
- Save the cronjobs file.
- Now update the "root" user IDs "crontab" with the following:
bash code crontab cronjobs
- Reboot the server and rsnapshot will be operational.
Email reporting
- To email a report of backups:
* above indicates an rsnapshot version number
bash code cp /usr/share/doc/rsnapshot*/utils/rsnapreport.pl /root
chmod 744 rsnapreport.pl
- Add the following to crontab for a weekly email report on rsnapshot:
Please Note: The above information maybe out of date due to technology changes. Please feel to update as required.
- 0 */4 * * * /usr/bin/rsnapshot hourly 2>&1 | /root/rsnapreport.pl > /root/rsnapreport
- 00 22 * * 6 /usr/bin/rsnapshot du >> /root/rsnapreport | nail –r "somereturnadress@provider.com" -s"HDA backup report" -S smtp=smtp.yourprovider.com youremail@provider.com < /root/rsnapreport
Make your backups available on clients (READ ONLY)
If you want to make the backups accesible from your clients:
Create a //hda/backup share in the HDA webinterface
add a read only NFS export:
- chkconfig nfs --level 2345 on
add
- nano /etc/exports
Save file
- /media/usbdisk/.private/.snapshots/ 127.0.0.1(ro,no_root_squash)
Unfortunately mounting an NFS share in fstab did not work on my machine after a reboot, so I chose an alternative configuration that mounts the share later in the booting process:
Add
- nano /etc/rc.local
save file
- mount -r -t nfs localhost:/media/usbdisk/.private/.snapshots/ /var/hda/files/backup/
Backing up owncloud
Backup and Recovery of ownCloud
Have
you been backing up your current ownCloud instance? If not, perhaps
it's time? Think of all that time spent doing the setup and all that
important data now stored in your ownCloud. Do you really want to take a chance losing the ownCloud configuration and all that stored data? Don't make it a "round to it" make it a "do it".
Following information will be provided to "backup and recover" data specific to ownCloud. No attempts will be made to discuss "philosophies" for backup and recover. The rsnapshot application will be used to backup data for an ownCloud instance and stored files. rnapshot does not perform the recovery of data and files. Recovery from the data backups will be done by other methods. Additionally, information provided is based on a Fedora platform.
The key directories of concern are:
Please notice that the stored data files used in this discussion are for the default "Amahi shares" directories for the sake of keeping the discussion less confusing.
Follow the following configuration steps:
Please Note: Items in the configuration file are separated by "tab" characters and NOT multiple spaces.
"rsync" has the following syntax on a command-line:
Main ownCloud Page
Following information will be provided to "backup and recover" data specific to ownCloud. No attempts will be made to discuss "philosophies" for backup and recover. The rsnapshot application will be used to backup data for an ownCloud instance and stored files. rnapshot does not perform the recovery of data and files. Recovery from the data backups will be done by other methods. Additionally, information provided is based on a Fedora platform.
Contents |
| ownCloud Tip! | |
|---|---|
| Before going further please become acquainted with the "rsnapshot" Wiki article. |
Key Directories
Before getting started a discussion of the directories referred in this section need to be explained.The key directories of concern are:
- The directories storing the ownCloud application binaries.
- The directories for the stored ownCloud data files.
- The backup directories for the ownCloud binaries, stored files, and the ownCloud database.
Please notice that the stored data files used in this discussion are for the default "Amahi shares" directories for the sake of keeping the discussion less confusing.
ownCloud Binary Directories
| The "web-apps" (red folder) directory structure is where application binaries for Amahi are stored. Below is the "owncloud-html branch". Under this branch is a collection of directories containing binaries for the ownCloud application. The "config" directory in particular is important as it contains files containing configuration and sharing information for an ownCloud instance. This directory is important when re-installing (recovery), updating, or upgrading (see "Upgrading ownCloud to New Version Releases") ownCloud. |
ownCloud Data Directories
| The "files" directory (red folder) referenced here is a typical Amahi shares structure. The "owncloud-data branch" is where physical files are stored in ownCloud. It is also important to note that "meta-data" for physicial files is kept in the ownCloud database (file sharing, groups). Therefore, it is important no only to backup the physical files but also the ownCloud database. |
rsnapshot Backup Directories
| The "backups" directory (red folder) shown here is located in the
same filesystem location as the Amahi hda structures. This is not a recommended practice
as the backups directory could be on the same hard disk(s) as the hda
directories, it is only intended as an example for this article only.
Normally the backups directory structure should be stored in a separate
hard disk assembly (i.e. external drive) from the source hda structures.
The "daily.0" is created by the rsnapshot application to store "snapshot-like" backups. This particular directory name is typical of the doing a "daily" backup with rsnapshot. The directories "daily.x" and "daily.y" are just pseudo names where each value of x and y are normally numbers indicating later version numbers of rnsapshot backup sets. If rsnapshot daily backups are set for a 7 day retention the numbering would be 0 to 6, where daily.0 is the most recent backup set and 6 the latest set. Below each "daily.?" backup set a directory (green folder) is created, normally intended for identifying a server name (default is localhost), for the purpose of this example "owncloud" is treated as the "server". Under the "owncloud server directory" structure there are branches containing backups of the ownCloud binaries, physical files, and "database dump". The "database_dump" directory contains a backup of the ownCloud database. rsnapshot can be configured to add additional branches under the owncloud server directory to store other backup data. |
Configure
This section shows how to configure rsnapshot for backing up ownCloud binaries, physical files, and the ownCloud database information based on the previous key directories discussion. Minimal information for each configuration setting will be provided. For details refer to the Amahi rsnapshot wiki article or the rnapshot web site.Follow the following configuration steps:
- Make sure that rsnapshot is installed. Fedora and Ubuntu distributions have packages available for the software.
- Open a "terminal" session and login to the "root" user ID.
- Move to the "/var/hda" directory.
- Create the "backups" directory and set permissions/ownership.
bash code cd /var/hda
mkdir backups
chmod 755 backups
chown root:root backups
- Move to the "/etc" directory.
bash code cd /etc
- Make a backup copy of the rsnapshot configuration file. Why? So that there is a reference just in case.
bash code cp rsnapshot.conf rsnapshot.conf.bkup
- Now using a favourite editor, open the "rnapshot.conf" file.
Please Note: Items in the configuration file are separated by "tab" characters and NOT multiple spaces.
- Find the "SNAPSHOT ROOT DIRECTORY" section and change "snapshot_root" to path where the backups will be stored.
Text snapshot_root /var/hda/backups/
- Find the "BACKUP INTERVALS" section and change the line items. What does this all mean? The "#" character at the beginning of each line means the configuration line item will not be enabled. The "#" is know to set a line to be a "comment" line. The "interval daily" line will be active and 7 days of backups will be kept.
Text #interval hourly 6
interval daily 7
#interval weekly 4
#interval monthly 1
- Find the "logfile" line and change the line item. The rsnapshot log file will be kept under the "backups" directory.
Text logfile /var/hda/backups/logs/rsnapshot
- Find the "BACKUP POINTS / SCRIPTS" section. Add changes as seen below. This is the section that defines the "key directories" source that will be backed up. See the "owncloud/" at the end of each line? Remember the previous "green" server folder? This is where the ownCloud binaries and physical files will be stored.
Text backup /var/hda/files/ owncloud/
backup /var/hda/web-apps/owncloud/ owncloud/
- Next find the line "Backup OwnCloud MySQL database" change as shown below. This set the location where the ownCloud "database dump" backup will be kept. Also the line shows the execution path for the database backup program script file that performs the database backup.
Text backup_script /usr/local/bin/backup_mysql.sh owncloud/database_dump
- Save the "rsnapshot.conf" file and return to the command-line prompt.
- Next database backup program script file has to be set up.
- Copy database backup scripts to the "/usr/local/bin/".
bash code cp /usr/share/doc/rsnapshot*/utils/backup_mysql.sh /usr/local/bin/
cp /usr/share/doc/rsnapshot*/utils/mysqlbackup.pl /usr/local/bin/
- * - indicates rsnapshot version number
- Go to the "/usr/local/bin/" directory and set the script file permissions and ownership.
bash code cd /usr/local/bin/
chown root:root /usr/local/bin/backup_mysql.sh
chown root:root /usr/local/bin/mysqlbackup.pl
chmod 754 /usr/local/bin/backup_mysql.sh
chmod 754 /usr/local/bin/mysqlbackup.pl
- Edit the "backup_mysql.sh" file.
- Find the line "backup the database" and add the line has shown below. This will be the command that will be issued to do the database backup. The database dump file will be called "owncloud_db.sql".
Text /usr/bin/mysqldump -uowncloud -powncloud owncloud > owncloud_db.sql
- Find the line "# make the backup readable only by root" and add the line shown below.
Text /bin/chmod 600 owncloud_db.sql
- Save the "backup_mysql.sh" file and return to the command-line prompt.
- There rsnapshot is configured to backup ownCloud.
Test
- Now the changes to the rsnapshot configuration file have to be tested. rsnapshot has a feature to test changes to make sure things have been setup correctly.
- Enter the following on the command-line to initiate the test.
bash code rsnapshot configtest
- When the test completes the following should be displayed:
Text Syntax OK
- If an error occurs the rsnapshot configuration file will need to be checked.
Backup
- The following command-line entry will perform the backup:
bash code rsnapshot daily
- The first time that rsnapshot runs could take sometime, each subsequent run should be quicker (depending on data changes).
- The following directories are created over time under the "backups" directory:
Text drwxr-xr-x 3 root root 4096 Feb 15 01:30 daily.0
drwxr-xr-x 3 root root 4096 Feb 14 01:30 daily.1
drwxr-xr-x 3 root root 4096 Feb 13 01:30 daily.2
drwxr-xr-x 3 root root 4096 Feb 12 01:30 daily.3
drwxr-xr-x 3 root root 4096 Feb 11 01:30 daily.4
drwxr-xr-x 3 root root 4096 Feb 10 01:30 daily.5
drwxr-xr-x 3 root root 4096 Feb 9 01:30 daily.6
drwxr-xr-x 2 root root 4096 Jan 20 09:38 logs
- As mentioned before, notice that the "daily.0" directory is the most recent backup version.
Recovery
This section will discuss restoring, updating, and upgrading parts of ownCloud from backups. ownCloud recovery from backups use the "rsync" command and must be used by the "root" user ID on an Amahi server. "rsync" is run from the "command-line"."rsync" has the following syntax on a command-line:
rsync [options] source-path destination-path where "[options]" will be set to "-avr --delete" for ownCloud restores: -a - archive, mode which includes the use of multiple rsync options. -v - verbose, reports all activity rsync performs during a restore. -r - recursive, include the sub-directories and their contents during a restore. -- delete - delete extraneous directories and files from the destination path directories during a restore.
Restore ownCloud
The following steps will restore the ownCloud binaries and configuration.- Go to the Amahi Dashboard, Apps => Installed make sure that ownCloud is uninstalled.
- If ownCloud is still installed, uninstall the current ownCloud instance. This will remove the ownCloud binaries and ownCloud database.
- Go to the Amahi Dashboard, Apps => Available, install ownCloud.
- Go to a "terminal" session and login to the "root" user ID.
- Restore the ownCloud "config" directory from the most recent backups with the following:
bash code rsync -avr --delete /var/hda/backups/daily.0/owncloud/var/hda/web-apps/owncloud/html/config /var/hda/web-apps/owncloud/html/
- Restore the ownCloud "apps" directory from the most recent backups with the following:
bash code rsync -avr --delete /var/hda/backups/daily.0/owncloud/var/hda/web-apps/owncloud/html/apps /var/hda/web-apps/owncloud/html/
- Restore the ownCloud database from the most recent backups using the database dump file:
bash code mysql -u owncloud -powncloud owncloud < /var/hda/backups/daily.0/owncloud/database_dump/owncloud_db.sql
- Login to ownCloud using a normal user ID and test ownCloud functionality (i.e. sharing) and applications.
- If the prior testing was successful have other users test their ownCloud IDs.
- The restore of ownCloud is now completed.
Restore ownCloud Files
The section describes the "rsync" command to be used to restore the ownCloud "files" directory structure.- Before doing the "files" restore make sure that there is enough disk storage room.
- Enter the following "rsync" command to restore the "files" directory from the most recent backups. Depending on the amount of data stored the restore could take sometime.
bash code rsync -avr --delete /var/hda/backups/daily.0/owncloud/var/hda/files /var/hda/
ownCloud Update and Upgrade
This section briefly describes the "rsync" restore commands that can be used when doing an "upgdate" or "upgrade" of ownCloud.| ownCloud Tip! | |
|---|---|
| Before going further please become acquainted with the Upgrading ownCloud to New Version Releases Wiki article. |
Update
- Restore the ownCloud "config" directory from the most recent backups with the following:
bash code rsync -avr --delete /var/hda/backups/daily.0/owncloud/var/hda/web-apps/owncloud/html/config /var/hda/web-apps/owncloud/html/
- Restore the ownCloud "apps" directory from the most recent backups with the following:
bash code rsync -avr --delete /var/hda/backups/daily.0/owncloud/var/hda/web-apps/owncloud/html/apps /var/hda/web-apps/owncloud/html/
- The following command-line entry will restore the ownCloud database from the most recent backups:
bash code mysql -u owncloud -powncloud owncloud < /var/hda/backups/daily.0/owncloud/database_dump/owncloud_db.sql
Upgrade
- Restore the ownCloud "config" directory from the most recent backups with the following:
bash code rsync -avr --delete /var/hda/backups/daily.0/owncloud/var/hda/web-apps/owncloud/html/config /var/hda/web-apps/owncloud/html/
- The following command-line entry will restore the ownCloud database from the most recent backups:
bash code mysql -u owncloud -powncloud owncloud < /var/hda/backups/daily.0/owncloud/database_dump/owncloud_db.sql
Automate
Backup and recovery can be automated in order to reduce the amount of manual command-line work required for these operations.- A "root" user "cron job" could be created to perform backups at say "1:30 AM" everyday.
root user "crontab" configuration:
Text 30 01 * * * /usr/bin/rsnapshot daily
- Some system administrators will create a "nighttime backup script" cron job that is executed at say "1:30 AM" before a server is shutdown each night.
root user "crontab" configuration:
Text 30 01 * * * /root/scripts/nighttime.bash
root user "nighttime.bash" script:
bash code nighttime.bash
#!/bin/bash
# Night time operations: Backup and Shutdown
# Backup Data
echo "Backup Start: "$(date)
/usr/bin/rsnapshot daily
echo "Backup Finished: "$(date)
# Send shutdown message
wall -n "$(date +%A) @ $(date +%T) system shutting down at scheduled time."
# Shutdown System
/sbin/shutdown -h now
Amahi ownCloud Backup/Recovery Tools
In order to make life easier for doing ownCloud backup and recovery a couple of tools might be of some benefit? The tools provided are based on the wiki articles "Backup and Recovery of ownCloud" and "Upgrading ownCloud to New Version Releases". Both tools can be modified to meet the needs of a current ownCloud instance. The tools can be found at directory location, "/var/hda/web-apps/owncloud/html/scripts/". Please remember if the tools are "modified", whether they are left in place or put elsewhere, to back them up as in a next install of ownCloud they will be replaced with the Amahi package defaults.Backup Tool
The backup tool is called,"oc-backup.sh". Currently it is configured to only do an "rsnapshot daily". The tool is run using the "root" user ID in a "terminal session".Help information is available by:
bash code /var/hda/web-apps/owncloud/html/scripts/oc-backup.sh -h
Resulting in the following:The tool only allows one command-line option to be entered. Please note the "-d" option? This performs the backup.
Text Usage:
oc-backup.sh [option]
Options:
-h help
--version displays version of this script
-d do daily backup
Recovery Tool
The backup tool is called \,"oc-recover.sh". The recovery tool performs several different types of ownCloud recovery operations.Help information is available by:
bash code /var/hda/web-apps/owncloud/html/scripts/oc-recover.sh -h
Resulting in the following:The tool only allows one command-line option to be entered.
Text Usage:
oc-recover.sh [option]
Options:
-h help
-f restore data files
-r restore ownCloud
-p update ownCloud
-g upgrade ownCloud
-rf or -fr restore ownCloud and ownCloud data files
-pf or -fp update ownCloud and ownCloud data files
-gf or -fg upgrade ownCloud and ownCloud data files
--version displays version of this script
Main ownCloud Page
Setting up HTB on Centos 6
The Hierarchical Token Bucket Quality of Service (HTB QoS) system is a
great tool to use for controlling the bandwidth of a network link,
especially when you have a bunch of doggs on your network that love to
use up all the internets they can get! Lets take a look at a quick and
simple HTB QoS setup on a CentOS 6 Linux box.
First, go to Google and run some bandwidth tests in order to get a good idea of your actual line speed. Take note of your maximum upload and download speeds. On my home network, I measured around 23Mbit down and 1Mbit up. Write these numbers down and save them for later…
Next, make sure that you have the iproute package installed, to install the necessary prerequisite programs.
You will notice in the /etc/sysconfig/htb/ folder that there are a number of different files, with some slightly different names. The first file we’ll look at, eth0, is just to specify what device we are working with. Inside this file are lines setting the default rule (the one used when no others match), and our R2Q. Note that the rate divided by R2Q gives us our quantum, which is the amount of bandwidth given to one class before servicing another class. The faster your available network connection, the larger your quantum can be. I’m using a r2q of 100, however you can always adjust this value depending on your needs and bandwidth speed. Below are the contents of the eth0 file:
Finally, we have our rules files. I set my ssh traffic to be given a minimum of 128Kbit, and a maximum of 20Mbit. This traffic also has the highest priority, in order to increase the availability of bandwidth to ssh traffic. A similar setup is done for the www traffic, and the default traffic. Below are the three files defining these classes…
eth0-2:10.ssh
The image below illustrates the hierarchy within this specific setup.

Now, in order to start using the rules and make them persistent on every reboot, we will add the htb.init service to the system, set it to start on boot, and turn it on right now! The commands below will do this for us:
Take a look at the htb.init-v0.8.5 we downloaded earlier for some more rule examples, as well as explainations of the configuration options.
Also check out the following websites for some more information on HTB QoS network traffic control.
HTB Linux queuing discipline manual – user guide
Linux Advanced Routing & Traffic Control HOWTO
First, go to Google and run some bandwidth tests in order to get a good idea of your actual line speed. Take note of your maximum upload and download speeds. On my home network, I measured around 23Mbit down and 1Mbit up. Write these numbers down and save them for later…
Next, make sure that you have the iproute package installed, to install the necessary prerequisite programs.
# yum install iprouteNow we can download the necessary htb.init script and examples to get us started. The htb.init script can be downloaded from here. Stick this script in your /etc/init.d/ directory. Next, download the example files and put them into the /etc/sysconfig/htb/ directory. Below are the commands I ran…
# wget http://sourceforge.net/projects/htbinit/files/HTB.init/0.8.5/htb.init-v0.8.5/download # mv htb.init-v0.8.5 /etc/init.d/htb.init # chmod 755 /etc/init.d/htb.init # wget http://downloads.sourceforge.net/project/htbinit/Examples/LARTC/htb-lartc.tar.gz # mkdir htb # tar zxf htb-lartc.tar.gz -C ./htb # mv ./htb /etc/sysconfig/Now, one other set of commands I want to run, to slightly change the names of the htb files to fit my needs. I am only going to have two classes of traffic, plus the default. I want to make sure my www and ssh connections each have a separate allocated bucket of bandwidth, and everything else can share the default bucket. The commands below will rename the htb configuration files to match. Please note that we are using the eth0 device in this example, since it is our internet connection.
# cd /etc/sysconfig/htb # mv eth0-2\:10.www eth0-2\:10.ssh # mv eth0-2\:20.smtp eth0-2\:20.wwwOk! Now that we have the init script in place, and the rules files in place, we can actually start some bandwidth shaping!
You will notice in the /etc/sysconfig/htb/ folder that there are a number of different files, with some slightly different names. The first file we’ll look at, eth0, is just to specify what device we are working with. Inside this file are lines setting the default rule (the one used when no others match), and our R2Q. Note that the rate divided by R2Q gives us our quantum, which is the amount of bandwidth given to one class before servicing another class. The faster your available network connection, the larger your quantum can be. I’m using a r2q of 100, however you can always adjust this value depending on your needs and bandwidth speed. Below are the contents of the eth0 file:
# eth0 device DEFAULT=99 R2Q=100Next, the eth0-2.root file. This specifies the default rate, ceiling rate, and burst speed. The default rate is the minimum rate for the class (device eth0 in this case). The ceiling rate is the maximum rate for the class. Finally, the burst rate is the maximum amount of bandwidth that can be sent through the hardware without moving on to service another class. Below are the contents of the eth0-2.root file:
# root class containing total bandwidth RATE=20Mbit CEIL=20Mbit BURST=1MbitNotice here that we are setting the rates at 20Mbit, which is below our maximum tested rate of 23Mbit. By setting our rate lower than the actual link rate, we limit the buffering done by any network equipment beyond our router (like the cable/DSL modem). This will decrease our lag time by keeping any traffic buffers on our faster equipment. I will gladly sacrifice a small amount of total speed for lower latency.
Finally, we have our rules files. I set my ssh traffic to be given a minimum of 128Kbit, and a maximum of 20Mbit. This traffic also has the highest priority, in order to increase the availability of bandwidth to ssh traffic. A similar setup is done for the www traffic, and the default traffic. Below are the three files defining these classes…
eth0-2:10.ssh
# class for SSH traffic RATE=128Kbit CEIL=20Mbit PRIO=1 RULE=*:22, RULE=*:22 LEAF=sfqeth0-2:20.www
# class for WWW traffic RATE=128Kbit CEIL=20Mbit PRIO=2 RULE=*:80, RULE=*:443, RULE=*:8008, RULE=*:8080, RULE=*:80 RULE=*:443 RULE=*:8008 RULE=*:8080 LEAF=sfqeth0-2:99.dfl
# class for all other traffic RATE=128Kbit CEIL=20Mbit PRIO=7 LEAF=sfqNow, lets take a look at the RULE= lines from the eth0-2:10.ssh file above.
RULE=*:22, RULE=*:22Rules are specified with the pattern RULE=[[saddr[/prefix]][:port[/mask]],][daddr[/prefix]][:port[/mask]], so the first line, RULE=*:22, will match all traffic with a source port of 22. The second line, RULE=*:22 matches any traffic with a destination of port 22. We do the same thing with the appropriate port numbers for our www class in order to shape our www traffic. There are many options here, since this is where we control what traffic matches which class; you can specify traffic by source port, destination port, source IP, destination IP, or a combination of them! Take a look at the links below for some more examples. Finally, the default rule will apply to any traffic which does not match our first two rules.
The image below illustrates the hierarchy within this specific setup.
Now, in order to start using the rules and make them persistent on every reboot, we will add the htb.init service to the system, set it to start on boot, and turn it on right now! The commands below will do this for us:
# chkconfig --add htb.init # chkconfig htb.init on # service htb.init startIf you get a warning along the lines of find: warning: you have specified the -maxdepth option after a non-option argument -type, but options are not positional then you will need to uncomment the following line in your /etc/init.d/htb.init script:
HTB_BASIC="yes"Using this simple HTB QoS setup, we can provide network bandwidth control to our small home network, preventing any one dogg from hogging all the internets! This setup will also scale fairly well to much larger installations.
Take a look at the htb.init-v0.8.5 we downloaded earlier for some more rule examples, as well as explainations of the configuration options.
Also check out the following websites for some more information on HTB QoS network traffic control.
HTB Linux queuing discipline manual – user guide
Linux Advanced Routing & Traffic Control HOWTO
Subscribe to:
Posts (Atom)



