-
-
Save techris45/9dc1460cb4d2e204e349f274c8cd78f2 to your computer and use it in GitHub Desktop.
Revisions
-
Daniel Hansson revised this gist
Jul 14, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ #!/bin/sh # # This script is used on a QNAP TS-269 PRO. https://www.en0ch.se/qnap-and-rsync/ # -
Daniel Hansson revised this gist
Jun 27, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -93,7 +93,7 @@ ssh -p22 [email protected] "mysqldump \ | bzip2" > $SHAREUSR/$TODAY/db/$TODAY.sql.bz2 # Un-hash this if you want to remove old backups (older than 2 days) # rm -R $SHAREUSR/$OLDBACKUP # Writes a log of successful updates echo "BACKUP success-$TODAY" >> $LOG -
Daniel Hansson revised this gist
Jun 23, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -18,7 +18,7 @@ RSYNC="/usr/bin/sudo /usr/bin/rsync" # Set the folderpath on the QNAP # Dont't forget to mkdir $SHAREUSR SHAREUSR="/share/CACHEDEV1_DATA/yourserver.se" # This is a list of files to ignore from backups. # Dont't forget to touch $EXCLUDES -
Daniel Hansson revised this gist
Jun 23, 2015 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -38,7 +38,7 @@ SOURCE="[email protected]:/folder-you-want-to-backup" DESTINATION="$SHAREUSR/$TODAY/" # Keep database backups in a separate directory. mkdir -p $SHAREUSR/$TODAY/db # This command rsync's files from the remote server to the local server. # Flags: @@ -85,7 +85,7 @@ rsync -zavx -e 'ssh -p22' \ # preferable to back up each database to a separate file. If you do that, I # suggest adding a configuration file that is looped over with a bash for() # loop. ssh -p22 [email protected] "mysqldump \ --user=root \ --password=SUPERSECRET \ --all-databases \ -
Daniel Hansson revised this gist
Jun 21, 2015 . 2 changed files with 3 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,7 +6,8 @@ # 1. $SHAREUSR # 2. $EXCLUDES (if you want o change the name of the file servername.excludes) # 3. $SOURCE & $DESTINATION # 4. [email protected] for the mysqldump # 5. --password=SUPERSECRET TODAY=`date +"%Y%m%d"` YESTERDAY=`date -d "1 day ago" +"%Y%m%d"` This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,6 +8,4 @@ /run /lost+found /var/tmp /var/lib/mysql/ -
Daniel Hansson revised this gist
Jun 21, 2015 . 1 changed file with 8 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,12 @@ #!/bin/bash # # This script is used on a QNAP TS-269 PRO. https://www.en0ch.se/qnap-and-rsync/ # # You have to change: # 1. $SHAREUSR # 2. $EXCLUDES (if you want o change the name of the file servername.excludes) # 3. $SOURCE & $DESTINATION # 4. TODAY=`date +"%Y%m%d"` YESTERDAY=`date -d "1 day ago" +"%Y%m%d"` @@ -16,7 +21,7 @@ SHAREUSR="/share/yourserver.se" # This is a list of files to ignore from backups. # Dont't forget to touch $EXCLUDES EXCLUDES="$SHAREUSR/servername.excludes" #LOG file # Dont't forget to touch $LOG @@ -81,7 +86,7 @@ rsync -zavx -e 'ssh -p22' \ # loop. ssh [email protected] "mysqldump \ --user=root \ --password=SUPERSECRET \ --all-databases \ --lock-tables \ | bzip2" > $SHAREUSR/$TODAY/db/$TODAY.sql.bz2 -
Daniel Hansson revised this gist
Jun 21, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -16,7 +16,7 @@ SHAREUSR="/share/yourserver.se" # This is a list of files to ignore from backups. # Dont't forget to touch $EXCLUDES EXCLUDES="/share/yourserver.se.excludes" #LOG file # Dont't forget to touch $LOG -
Daniel Hansson revised this gist
Jun 21, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -81,7 +81,7 @@ rsync -zavx -e 'ssh -p22' \ # loop. ssh [email protected] "mysqldump \ --user=root \ --password=Danielen0ch# \ --all-databases \ --lock-tables \ | bzip2" > $SHAREUSR/$TODAY/db/$TODAY.sql.bz2 -
Daniel Hansson revised this gist
Jun 21, 2015 . 1 changed file with 17 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -69,13 +69,24 @@ mkdir -p /$SHAREUSR/$TODAY/db # authentication use a password-less SSH key only allowed read permissions by # the backup server's root user. rsync -zavx -e 'ssh -p22' \ --rsync-path="$RSYNC" \ --exclude-from=$EXCLUDES \ --numeric-ids \ --delete -r \ --link-dest=../$YESTERDAY $SOURCE $DESTINATION # Backup all databases. I backup all databases into a single file. It might be # preferable to back up each database to a separate file. If you do that, I # suggest adding a configuration file that is looped over with a bash for() # loop. ssh [email protected] "mysqldump \ --user=root \ --password="SUPERSECRETPASSWORD" \ --all-databases \ --lock-tables \ | bzip2" > $SHAREUSR/$TODAY/db/$TODAY.sql.bz2 # Un-hash this if you want to remove old backups (older than 2 days) # rm -R $OLDBACKUP # Writes a log of successful updates -
Daniel Hansson revised this gist
Jun 21, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ #!/bin/bash # # This script is used on a QNAP TS-269 PRO. https://www.en0ch.se/qnap-and-rsync/ # TODAY=`date +"%Y%m%d"` -
Daniel Hansson revised this gist
Jun 21, 2015 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,7 @@ #!/bin/bash # # This script is used on a QNAP TS-269 PRO. # TODAY=`date +"%Y%m%d"` YESTERDAY=`date -d "1 day ago" +"%Y%m%d"` -
Daniel Hansson revised this gist
Jun 21, 2015 . 1 changed file with 9 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -71,6 +71,12 @@ rsync -zavx -e 'ssh -p22' \ --numeric-ids \ --delete -r \ --link-dest=../$YESTERDAY $SOURCE $DESTINATION # Un-hash this if you want to remove old backups (older than 2 days) # rm -R $OLDBACKUP # Writes a log of successful updates echo "BACKUP success-$TODAY" >> $LOG # Clean exit exit 0 -
Daniel Hansson revised this gist
Jun 21, 2015 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,7 +5,9 @@ /mnt /swapfile /tmp /run /lost+found /var/tmp /var/lib/mysql/ -
Daniel Hansson revised this gist
Jun 21, 2015 . 1 changed file with 8 additions and 18 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -23,9 +23,10 @@ LOG="$SHAREUSR/BACKUP_success.log" # backups that are particularly large (other than the initial backup), but that # you will be creating thousands of hardlinks on disk that will consume inodes. # Source and Destination SOURCE="[email protected]:/folder-you-want-to-backup" DESTINATION="$SHAREUSR/$TODAY/" # Keep database backups in a separate directory. mkdir -p /$SHAREUSR/$TODAY/db @@ -34,11 +35,14 @@ mkdir -p /$SHAREUSR/$TODAY/db # Flags: # -z enables gzip compression of the transport stream. # -e enables using ssh as the transport prototcol. # -a preserves all file attributes and permissions. # -x (or --one-file-system) Don’t cross filesystem boundaries # -v shows the progress. # --rsync-path lets us pass the remote rsync command through sudo. # --exclude-from points to our configuration of files and directories to skip. # --numeric-ids is needed if user ids don't match between the source and # destination servers. # --delete -r(ecursive) Deletes files from $DESTINATION that are not present on the $SOURCE # --link-dest is a key flag. It tells the local rsync process that if the # file on the server is identical to the file in ../$YESTERDAY, instead # of transferring it create a hard link. You can use the "stat" command @@ -69,18 +73,4 @@ rsync -zavx -e 'ssh -p22' \ --link-dest=../$YESTERDAY $SOURCE $DESTINATION # Backup all databases. I backup all databases into a single file. It might be # prefer -
Daniel Hansson revised this gist
Jun 21, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -81,6 +81,6 @@ ssh [email protected] "mysqldump \ rm -R $OLDBACKUP echo "BACKUP success-$TODAY" >> $LOG exit 0 -
Daniel Hansson revised this gist
Jun 21, 2015 . 1 changed file with 11 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,23 +6,29 @@ OLDBACKUP=`date -d "2 days ago" +"%Y%m%d"` # Set the path to rsync on the remote server so it runs with sudo. RSYNC="/usr/bin/sudo /usr/bin/rsync" # Set the folderpath on the QNAP # Dont't forget to mkdir $SHAREUSR SHAREUSR="/share/yourserver.se" # This is a list of files to ignore from backups. # Dont't forget to touch $EXCLUDES EXCLUDES="$SHAREUSR.excludes" #LOG file # Dont't forget to touch $LOG LOG="$SHAREUSR/BACKUP_success.log" # Remember that you will not be generating # backups that are particularly large (other than the initial backup), but that # you will be creating thousands of hardlinks on disk that will consume inodes. DESTINATION="$SHAREUSR/$TODAY/" SOURCE="[email protected]:/folder-you-want-to-backup" # Keep database backups in a separate directory. mkdir -p /$SHAREUSR/$TODAY/db # This command rsync's files from the remote server to the local server. # Flags: @@ -71,7 +77,7 @@ ssh [email protected] "mysqldump \ --password="supersecretpassword" \ --all-databases \ --lock-tables \ | bzip2" > $SHAREUSR/$TODAY/db/$TODAY.sql.bz2 rm -R $OLDBACKUP -
Daniel Hansson revised this gist
Jun 21, 2015 . 1 changed file with 23 additions and 24 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,31 +1,28 @@ #!/bin/bash TODAY=`date +"%Y%m%d"` YESTERDAY=`date -d "1 day ago" +"%Y%m%d"` OLDBACKUP=`date -d "2 days ago" +"%Y%m%d"` # Set the path to rsync on the remote server so it runs with sudo. RSYNC="/usr/bin/sudo /usr/bin/rsync" # This is a list of files to ignore from backups. EXCLUDES="/share/yourserver.se.excludes" #LOG file LOG="/share/yourserver.se/BACKUP_success.log" # Remember that you will not be generating # backups that are particularly large (other than the initial backup), but that # you will be creating thousands of hardlinks on disk that will consume inodes. DESTINATION="/share/yourserver.se/$TODAY/" SOURCE="[email protected]:/folder-you-want-to-backup" # Keep database backups in a separate directory. mkdir -p /share/yourserver.se/$TODAY/db # This command rsync's files from the remote server to the local server. # Flags: @@ -58,24 +55,26 @@ mkdir -p /media/servername/db # Note the NOPASSWD option in the sudo configuration. For remote # authentication use a password-less SSH key only allowed read permissions by # the backup server's root user. rsync -zavx -e 'ssh -p22' \ --rsync-path="$RSYNC" \ --exclude-from=$EXCLUDES \ --numeric-ids \ --delete -r \ --link-dest=../$YESTERDAY $SOURCE $DESTINATION # Backup all databases. I backup all databases into a single file. It might be # preferable to back up each database to a separate file. If you do that, I # suggest adding a configuration file that is looped over with a bash for() # loop. ssh [email protected] "mysqldump \ --user=root \ --password="supersecretpassword" \ --all-databases \ --lock-tables \ | bzip2" > /share/yourserver.se/$TODAY/db/$TODAY.sql.bz2 rm -R $OLDBACKUP echo "BACKUP success-`date +"%Y%m%d"`" >> $LOG exit 0 -
deviantintegral revised this gist
Apr 17, 2012 . 1 changed file with 11 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ /dev /proc /sys /media /mnt /swapfile /tmp /var/tmp /var/lib/mysql/ /var/lib/varnish/servername -
deviantintegral revised this gist
Apr 17, 2012 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -25,7 +25,7 @@ DESTINATION="/media/servername/$TODAY/" mount /media/servername # Keep database backups in a separate directory. mkdir -p /media/servername/db # This command rsync's files from the remote server to the local server. # Flags: -
deviantintegral renamed this gist
Apr 17, 2012 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
deviantintegral created this gist
Apr 17, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,81 @@ #!/bin/bash # This is a simple backup script that uses rsync to backup files and does # complete mysql table dumps. Note that this script DOES NOT EXPIRE OLD BACKUPS. # Place it in /etc/cron.daily to execute it automatically. For hourly backups, # it will need to be placed in /etc/cron.hourly, and the $TODAY / $YESTERDAY # variables will need to be changed. TODAY=`date +"%Y%m%d"` YESTERDAY=`date -d "1 day ago" +"%Y%m%d"` # Set the path to rsync on the remote server so it runs with sudo. RSYNC="/usr/bin/sudo /usr/bin/rsync" # This is a list of files to ignore from backups. EXCLUDES="/etc/servername.excludes" # I use a separate volume for backups. Remember that you will not be generating # backups that are particularly large (other than the initial backup), but that # you will be creating thousands of hardlinks on disk that will consume inodes. DESTINATION="/media/servername/$TODAY/" # I like to keep the separate volume unmounted to save me from accidentally # nuking backups. mount /media/servername # Keep database backups in a separate directory. mkdir -p /media/media/servername/db # This command rsync's files from the remote server to the local server. # Flags: # -z enables gzip compression of the transport stream. # -e enables using ssh as the transport prototcol. # --rsync-path lets us pass the remote rsync command through sudo. # --archive preserves all file attributes and permissions. # --exclude-from points to our configuration of files and directories to skip. # --numeric-ids is needed if user ids don't match between the source and # destination servers. # --link-dest is a key flag. It tells the local rsync process that if the # file on the server is identical to the file in ../$YESTERDAY, instead # of transferring it create a hard link. You can use the "stat" command # on a file to determine the number of hard links. Note that when # calculating disk space, du includes disk space used for the first # instance of a linked file it encounters. To properly determine the disk # space used of a given backup, include both the backup and it's previous # backup in your du command. # # The "rsync" user is a special user on the remote server that has permissions # to run a specific rsync command. We limit it so that if the backup server is # compromised it can't use rsync to overwrite remote files by setting a remote # destination. I determined the sudo command to allow by running the backup # with the rsync user granted permission to use any flags for rsync, and then # copied the actual command run from ps auxww. With these options, under # Ubuntu, the sudo line is: # # rsync ALL=(ALL) NOPASSWD: /usr/bin/rsync --server --sender -logDtprze.iLsf --numeric-ids . / # # Note the NOPASSWD option in the sudo configuration. For remote # authentication use a password-less SSH key only allowed read permissions by # the backup server's root user. rsync -z -e "ssh" \ --rsync-path="$RSYNC" \ --archive \ --exclude-from=$EXCLUDES \ --numeric-ids \ --link-dest=../$YESTERDAY rsync@servername:/ $DESTINATION # Backup all databases. I backup all databases into a single file. It might be # preferable to back up each database to a separate file. If you do that, I # suggest adding a configuration file that is looped over with a bash for() # loop. ssh rsync@servername "mysqldump \ --user=root \ --password="my-super-secure-password" \ --all-databases \ --lock-tables \ | bzip2" > /media/servername/db/$TODAY.sql.bz2 # Remove this if you keep the backup directory mounted. umount /media/servername