Linux/SimpleBashBackup: Difference between revisions

From Wiki
No edit summary
 
(16 intermediate revisions by the same user not shown)
Line 1: Line 1:
== folder structure ==
== default folder structure ==
<pre>
<pre>
/srv
/srv
Line 15: Line 15:
           /03_monthly
           /03_monthly
</pre>
</pre>


== backupmanager.sh ==
== backupmanager.sh ==
Line 21: Line 20:
</pre>
</pre>


== exmaple jobs ==
== example jobs ==
* each job file needs to be located in one of the job folders (01_daily-jobs, 02_weekly-jobs, 03_monthly-jobs)
* each job file needs to end in .job
* the following variables are passed on from the main script
** BACKUPDIR -> path where the backupfile should be placed (e.g. /srv/backup-data/01_daily/2016-05-23)
** FILEDESC -> datecode to be used in the filename
** TEMPDIR -> can optionally be used for temp files
 
=== single folder ===
=== single folder ===
=== multiple folders ===
==== weak compression ====
=== clean old backups ===
<pre>
=== rsync backups to other server ===
ARCHIV="$BACKUPDIR/${FILEDESC}_server_srv_www.tar.gz"
tar -c /srv/www | pigz --best > $ARCHIV
</pre>
==== strong compression ====
<pre>
ARCHIV="$BACKUPDIR/${FILEDESC}_server_srv_www.tar.7z"
tar -c /srv/www | 7z a -m0=lzma2 -mx9 -si $ARCHIV
</pre>
=== multiple files/folders ===
<pre>
CURDIR=$(pwd)
ARCHIV="$BACKUPDIR/${FILEDESC}_hostname_srv.tar.gz
INCLUDE="--files-from=$CURDIR/backup_srv.include"
EXCLUDE="--exclude-from=$CURDIR/backup_srv.exclude"
tar $EXCLUDE -c $INCLUDE | pigz --best > $ARCHIV
</pre>
 
=== remove old backups, keep new backups ===
<pre>
KEEP="4"
cd $BACKUPDIR
cd ..
ls -r | sed -e 1,${KEEP}d | xargs rm -r
</pre>
 
=== rsync backup files to other ssh server ===
<pre>
rsync -avz -e ssh $BACKUPDIR username@hostnameoftarget:/srv/backup-data/targetfolder
</pre>
 
=== rsync backup from local to samba share ===
* /root/.smb_cred
<pre>
username=testuser
password=password1234
</pre>
* 70_mountcifs.job:
<pre>
mount -t cifs -o credentials=/root/.smb_cred //sambaserver/sambashare /mnt/localmountpoint
</pre>
* 71_remotesync.job:
<pre>
rsync -avz -P /srv/somelocalfolder /mnt/localmountpoint/destinationfolder
</pre>
* 73_unmountcifs.job:
<pre>
umount -l /mnt/localmountpoint
</pre>
 
=== mysql databases ===
[[Category:Linux/Bash]]
[[Category:Linux]]

Latest revision as of 13:53, 1 April 2017

default folder structure

/srv
    /backup
           /backupmanager.sh
           /01_daily-jobs
           /02_weekly-jobs
           /03_monthly-jobs
           /templates
           /tmp

    /backup-data
           /01_daily
           /02_weekly
           /03_monthly

backupmanager.sh


example jobs

  • each job file needs to be located in one of the job folders (01_daily-jobs, 02_weekly-jobs, 03_monthly-jobs)
  • each job file needs to end in .job
  • the following variables are passed on from the main script
    • BACKUPDIR -> path where the backupfile should be placed (e.g. /srv/backup-data/01_daily/2016-05-23)
    • FILEDESC -> datecode to be used in the filename
    • TEMPDIR -> can optionally be used for temp files

single folder

weak compression

ARCHIV="$BACKUPDIR/${FILEDESC}_server_srv_www.tar.gz"
tar -c /srv/www | pigz --best > $ARCHIV

strong compression

ARCHIV="$BACKUPDIR/${FILEDESC}_server_srv_www.tar.7z"
tar -c /srv/www | 7z a -m0=lzma2 -mx9 -si $ARCHIV

multiple files/folders

CURDIR=$(pwd)
ARCHIV="$BACKUPDIR/${FILEDESC}_hostname_srv.tar.gz
INCLUDE="--files-from=$CURDIR/backup_srv.include"
EXCLUDE="--exclude-from=$CURDIR/backup_srv.exclude"
tar $EXCLUDE -c $INCLUDE | pigz --best > $ARCHIV

remove old backups, keep new backups

KEEP="4"
cd $BACKUPDIR
cd ..
ls -r | sed -e 1,${KEEP}d | xargs rm -r

rsync backup files to other ssh server

rsync -avz -e ssh $BACKUPDIR username@hostnameoftarget:/srv/backup-data/targetfolder

rsync backup from local to samba share

  • /root/.smb_cred
username=testuser
password=password1234
  • 70_mountcifs.job:
mount -t cifs -o credentials=/root/.smb_cred //sambaserver/sambashare /mnt/localmountpoint
  • 71_remotesync.job:
rsync -avz -P /srv/somelocalfolder /mnt/localmountpoint/destinationfolder
  • 73_unmountcifs.job:
umount -l /mnt/localmountpoint

mysql databases