From: cwillu <cwillu@cwillu.com>
To: unlisted-recipients:; (no To-header on input)
Cc: linux-btrfs@vger.kernel.org
Subject: Re: birgers RFE #2
Date: Fri, 13 Aug 2010 17:23:38 -0600 [thread overview]
Message-ID: <AANLkTimSW05EqgtcfmMzujg-oMkHGwV-vacPyvHEDwSC@mail.gmail.com> (raw)
In-Reply-To: <1280845489.31210.20.camel@sch30110.bergens-tidende.no>
[-- Attachment #1: Type: text/plain, Size: 285 bytes --]
And none of them are what I would consider remotely useful for
backups. (What, you guys don't backup to external media?) :)
Attached is my nightly backup script, edit it to suit, and dump a
symlink into /etc/cron.daily or whatever. It requires a btrfs target
(rather than source).
[-- Attachment #2: backup --]
[-- Type: application/octet-stream, Size: 2785 bytes --]
#!/bin/bash
renice 20 $$
ionice -c3 -p$$
# export DISPLAY=:0
echo $(date) Starting backups >> /var/log/backup
# some day, make this find suitable drives automatically
BACKUP_TO_A="/media/drive_a/"
BACKUP_TO_B="/media/drive_b/"
# abort if there's no backup drive connected
mountpoint "$BACKUP_TO_A" && BACKUP_TO="$BACKUP_TO_A"
mountpoint "$BACKUP_TO_B" && BACKUP_TO="$BACKUP_TO_B"
mountpoint "$BACKUP_TO" || exit
YESTERDAY="$(ls -1t ${BACKUP_TO} | head -n 1)"
TODAY="$(date +%F)"
echo Will snapshot ${YESTERDAY} to ${TODAY} >> /var/log/backup
btrfs subvolume snapshot "${BACKUP_TO}/${YESTERDAY}" "${BACKUP_TO}/${TODAY}" || exit 1
BACKUP_TO="${BACKUP_TO}/${TODAY}"
echo $(date) Backing up to $BACKUP_TO >> /var/log/backup
eval `ssh-agent`
ssh-add
# Delete files which no longer exist in the destination,
# even if errors occur during the transfer. Exclude a handful
# of potentially troublesome directories (even though we use -x,
# .gvfs is often not readable by root)
STANDARD_PARMS="--delete --ignore-errors --exclude .local/share/Trash/ --exclude .gvfs/ --exclude /media/"
# List copied files, do the typical backup thing (attributes,
# mod-dates, etc), stay on the source filesystem, and use
# relative pathnames so that we can keep backup explicitely
# listed sub-mounts filesystems to the 'right' place.
PARMS="-vaxR $STANDARD_PARMS"
MOUNTS="-vaR $STANDARD_PARMS"
do_backup ()
{
TARGET_USER="$1"
TARGET_HOST="$2"
TARGET_PATH="$3"
echo $TARGET_HOST:$TARGET_PATH Try >> /var/log/backup
STORE_PATH="$BACKUP_TO/$TARGET_HOST"
ping -c 1 $TARGET_HOST && {
echo $(date) $TARGET_HOST:$TARGET_PATH Start >> /var/log/backup
mkdir -p $STORE_PATH
rsync $PARMS $TARGET_USER@$TARGET_HOST:$TARGET_PATH $STORE_PATH
echo $(date) $TARGET_HOST@$TARGET_PATH Complete >> /var/log/backup
}
}
do_local_backup ()
{
TARGET_PATH="$1"
STORE_PATH="$BACKUP_TO/local"
echo local:$TARGET_PATH Try >> /var/log/backup
# mountpoint $TARGET_PATH is not used because the mount point will
# often exist even if though the device isn't there. That would be
# a problem given that we delete files that are missing from the
# source; the --max-delete option is not a sane alternative solution.
find $TARGET_PATH -maxdepth 0 -not -empty -type d | grep / && {
echo $(date) local:$TARGET_PATH Start >> /var/log/backup
mkdir -p $STORE_PATH
rsync $PARMS $TARGET_PATH $STORE_PATH
echo $(date) local:$TARGET_PATH Complete >> /var/log/backup
}
}
do_backup root some-hostname-here / &
PARMS="$PARMS --exclude foo/ --exclude Music/" do_backup root some-other-hostname / &
do_local_backup / &
PARMS="$MOUNTS" do_local_backup /media/silly-windows-machine &
wait
ssh-agent -k
echo $(date) Backups completed >> /var/log/backup
next prev parent reply other threads:[~2010-08-13 23:23 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-08-03 14:24 birgers RFE #2 birger
2010-08-13 23:23 ` cwillu [this message]
-- strict thread matches above, loose matches on Subject: below --
2010-08-03 12:44 birger
2010-08-03 13:48 ` Xavier Nicollet
[not found] ` <AANLkTimizt+Eh+B+cViWXUBa9J1i0XVK2qU0bEmcVfMB@mail.gmail.com>
2010-08-03 13:51 ` Benjamin Griese
2010-08-03 14:33 ` Xavier Nicollet
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=AANLkTimSW05EqgtcfmMzujg-oMkHGwV-vacPyvHEDwSC@mail.gmail.com \
--to=cwillu@cwillu.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).