Changes

From Amahi Wiki
Jump to: navigation, search
image =oc_tip.png|
heading =ownCloud Tip!|
message = Before going further please become acquainted with the ''[[Rsnapshot|"rsnapshot"]]'' Wiki article.}}
<!--ownCloud Tip ends-->
=== Key Directories ===
|- valign="top"
| border="0" | [[File:Oc_backup_files_1c_v3.png |left]]
| border="0" | 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.
<br/>
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.
* Create the "backups" directory and set permissions/ownership.
<blockquote>{{Code| cd /var/hda mkdir backups chmod 755 backups chown root:root backups}}</blockquote>
* Move to the "/etc" directory.
<blockquote>{{Code| cd /etc}}</blockquote> 
* Make a backup copy of the rsnapshot configuration file. Why? So that there is a reference just in case.
<blockquote>{{Code| cp rsnapshot.conf rsnapshot.conf.bkup}}</blockquote>
* Now using a favourite editor, open the "rnapshot.conf" file.
* Find the "SNAPSHOT ROOT DIRECTORY" section and change "snapshot_root" to path where the backups will be stored.
<blockquote>{{Text|Text= snapshot_root /var/hda/backups/}}</blockquote>
* 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.
<blockquote>{{Text|Text= #interval hourly 6 interval daily 7
#interval weekly 4
#interval monthly 1
}}
</blockquote>
* Find the "logfile" line and change the line item. The rsnapshot log file will be kept under the "backups" directory.
<blockquote>{{Text|Text= logfile /var/hda/backups/logs/rsnapshot}}</blockquote>
* 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.
<blockquote>{{Text|Text= backup /var/hda/files/ owncloud owncloud/ backup /var/hda/web-apps/owncloud/ owncloud/}}</blockquote>
* 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.
<blockquote>{{Text|Text= backup_script /usr/local/bin/backup_mysql.sh owncloud/database_dump}}</blockquote> 
* 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 script to the "/usr/local/bin/".
<blockquote>{{Code| cp /usr/share/doc/rsnapshot*/utils/backup_mysql.sh /usr/local/bin/cp /usr/share/doc/rsnapshot*/utils/mysqlbackup.pl /usr/local/bin/}}</blockquote>
:'''*''' - indicates rsnapshot version number
* Go to the "/usr/local/bin/" directory and set the script file permissions and ownership.
<blockquote>{{Code| cd /usr/local/bin/ chown root:root /usr/local/bin/backup_mysql.shchown root:root /usr/local/bin/mysqlbackup.pl chmod 754 /usr/local/bin/backup_mysql.shchmod 754 /usr/local/bin/mysqlbackup.pl}}</blockquote>
* 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".
<blockquote>{{Text|Text= /usr/bin/mysqldump -uowncloud -powncloud owncloud > owncloud_db.sql}}</blockquote>
* Find the line "# make the backup readable only by root" and add the line shown below.
<blockquote>{{Text|Text= /bin/chmod 600 owncloud_db.sql}}</blockquote>
* Save the "backup_mysql.sh" file and return to the command-line prompt.
* Enter the following on the command-line to initiate the test.
<blockquote>{{Code| rsnapshot configtest}}</blockquote>
* When the test completes the following should be displayed:
<blockquote>{{Text|Text= Syntax OK}}</blockquote>
* If an error occurs the rsnapshot configuration file will need to be checked.
=== Backup ===
* The following command-line entry will perform the backup:
<blockquote>{{Code| rsnapshot daily}}</blockquote>
* 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:
 <blockquotepre>{{Text|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 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}}</blockquotepre
* As mentioned before, notice that the "daily.0" directory is the most recent backup version.
* Go to a "terminal" session and login to the "root" user ID.
* Restore the ownCloud "config.php" directory file from the most recent backups with the following:<blockquote>{{Code| rsync -avr --delete /var/hda/backups/daily.0/owncloud/var/hda/web-apps/owncloud/html/config /config.php /var/hda/web-apps/owncloud/html/}}<config/blockquote>
* Restore the ownCloud "apps" directory from the most recent backups with the following:
 <blockquotepre style="white-space: pre-wrap; word-break: keep-all;">{{Code|rsync -avr --delete /var/hda/backups/daily.0/owncloud/var/hda/web-apps/owncloud/html/apps /var/hda/web-apps/owncloud/html/}}</blockquotepre>
* Restore the ownCloud database from the most recent backups using the database dump file:
 :1. Recreate the database ('''THIS IS EXTREMELY IMPORTANT'''): mysqladmin -uowncloud -powncloud -f drop owncloud; mysqladmin -uowncloud -powncloud -f create owncloud; :2. Restore the database:<blockquotepre style="white-space: pre-wrap; word-break: keep-all;">{{Code|mysql -u owncloud -powncloud owncloud < /var/hda/backups/daily.0/owncloud/database_dump/owncloud_db.sql}}</blockquotepre
* 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.
 
* 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.
<blockquote>{{Code| rsync -avr --delete /var/hda/backups/daily.0/owncloud/var/hda/files /var/hda/}}</blockquote>
:'''NOTE:''' If using ownCloud 6or greater, change all instances of ''owncloud'' to ''owncloud<major release number> (i.e. owncloud6)''.
==== ownCloud Update and Upgrade ====
===== Update =====
* Restore the ownCloud "config.php" directory file from the most recent backups with the following:<blockquote>{{Code| rsync -avr --delete /var/hda/backups/daily.0/owncloud/var/hda/web-apps/owncloud/html/config /config.php /var/hda/web-apps/owncloud/html/}}<config/blockquote>
* Restore the ownCloud "apps" directory from the most recent backups with the following:
<blockquotepre style="white-space: pre-wrap; word-break: keep-all;">{{Code|rsync -avr --delete /var/hda/backups/daily.0/owncloud/var/hda/web-apps/owncloud/html/apps /var/hda/web-apps/owncloud/html/}}</blockquotepre>
* The following command-line entry will restore the ownCloud database from the most recent backups:
<blockquote>{{Code| mysql -u owncloud -powncloud owncloud < /var/hda/backups/daily.0/owncloud/database_dump/owncloud_db.sql}}</blockquote>
:'''NOTE:''' For all releases on or after ownCloud 6, change all instances of ''owncloud'' to ''owncloud6''.
===== Upgrade =====
* Restore the ownCloud "config.php" directory file from the most recent backups with the following:<blockquote>{{Code|rsync ​rsync -avr --delete /var/hda/backups/daily.0/owncloud/var/hda/web-apps/owncloud/html/config /config.php /var/hda/web-apps/owncloud/html/}}<config/blockquote>
* The following command-line entry will restore the ownCloud database from the most recent backups:
<blockquote>{{Code| mysql -u owncloud -powncloud owncloud < /var/hda/backups/daily.0/owncloud/database_dump/owncloud_db.sql}} :'''NOTE:''' For all releases on or after ownCloud 6, change all instances of ''owncloud'' to ''owncloud</blockquotemajor release number>(i.e. owncloud6)''.
=== Automate ===
* A "root" user "cron job" could be created to perform backups at say "1:30 AM" everyday.
<blockquote>root user "crontab" configuration:{{Text|Text= 30 01 * * * /usr/bin/rsnapshot daily}}</blockquote>
* 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.
<blockquote>root user "crontab" configuration:{{Text|Text= 30 01 * * * /root/scripts/nighttime.bash}}</blockquote>
<blockquote>root user "nighttime.bash" script:{{Code|<pre>nighttime.bash
#!/bin/bash
# Night time operations: Backup and Shutdown
wall -n "$(date +%A) @ $(date +%T) system shutting down at scheduled time."
# Shutdown System
/sbin/shutdown -h now}}</blockquotepre>
=== 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 The 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".
<blockquote>Help information is available by:{{Code| /var/hda/web-apps/owncloud/html/scripts/oc-backup.sh -h}}</blockquote>
<blockquote>Resulting in the following:{{Text|Text=<pre>Usage: oc-backup.sh [option]
Options:
-h help
--version displays version of this script
-d do daily backup}}</blockquotepre>
The tool only allows one command-line option to be entered. Please note the "-d" option? This performs the daily backupprocess.
==== Recovery Tool ====
The backup tool is called \,"oc-recover.sh". The recovery tool performs several different types of ownCloud recovery operations.
<blockquote>Help information is available by:{{Code| /var/hda/web-apps/owncloud/html/scripts/oc-recover.sh -h}}</blockquote>
<blockquote>Resulting in the following:{{Text|Text=<pre>Usage: oc-recover.sh [option]
Options:
-pf or -fp update ownCloud and ownCloud data files
-gf or -fg upgrade ownCloud and ownCloud data files
--version displays version of this script}}</blockquotepre>
The tool only allows one command-line option to be entered.
12,424

edits