Skip to content
This repository has been archived by the owner on Dec 27, 2021. It is now read-only.

Commit

Permalink
-U now also accepts tar/bsdtar options/allow tar in Fedora/show archi…
Browse files Browse the repository at this point in the history
…ve read errors in dialog interface
  • Loading branch information
tritonas00 committed Apr 6, 2014
1 parent cdb5a5b commit 13980cd
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 37 deletions.
21 changes: 5 additions & 16 deletions backup.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

BR_VERSION="System Tar & Restore 3.9.2"
BR_VERSION="System Tar & Restore 3.9.3"
BR_SEP="::"

color_variables() {
Expand Down Expand Up @@ -108,6 +108,9 @@ set_tar_options() {

if [ "$BRarchiver" = "tar" ]; then
BR_TAROPTS="--exclude=/run/* --exclude=/proc/* --exclude=/dev/* --exclude=/media/* --exclude=/sys/* --exclude=/tmp/* --exclude=/mnt/* --exclude=.gvfs --exclude=lost+found --sparse $BR_USER_OPTS"
if [ -f /etc/yum.conf ]; then
BR_TAROPTS="${BR_TAROPTS} --acls --xattrs --selinux"
fi
if [ "$BRhome" = "No" ] && [ "$BRhidden" = "No" ] ; then
BR_TAROPTS="${BR_TAROPTS} --exclude=/home/*"
elif [ "$BRhome" = "No" ] && [ "$BRhidden" = "Yes" ] ; then
Expand Down Expand Up @@ -263,7 +266,7 @@ while true; do
echo -e "
${BR_BOLD}$BR_VERSION
Interface:${BR_NORM}
General:${BR_NORM}
-i, --interface interface to use (cli dialog)
-N, --no-color disable colors
-q, --quiet dont ask, just run
Expand Down Expand Up @@ -306,11 +309,6 @@ if [ $(id -u) -gt 0 ]; then
exit
fi

if [ -f /etc/yum.conf ] && [ "$BRarchiver" = "tar" ]; then
echo -e "[${BR_RED}ERROR${BR_NORM}] Only bsdtar is supported on Fedora"
BRSTOP="y"
fi

if [ ! -d "$BRFOLDER" ] && [ -n "$BRFOLDER" ]; then
echo -e "[${BR_RED}ERROR${BR_NORM}] Directory does not exist: $BRFOLDER"
BRSTOP="y"
Expand All @@ -331,19 +329,10 @@ if [ -n "$BRinterface" ] && [ ! "$BRinterface" = "cli" ] && [ ! "$BRinterface" =
BRSTOP="y"
fi

if [ -f /etc/yum.conf ] && [ -z $(which bsdtar 2> /dev/null) ]; then
echo -e "[${BR_RED}ERROR${BR_NORM}] Package bsdtar is not installed. Install the package and re-run the script"
BRSTOP="y"
fi

if [ -n "$BRSTOP" ]; then
exit
fi

if [ -f /etc/yum.conf ]; then
BRarchiver="bsdtar"
fi

if [ -z "$BRhidden" ]; then
BRhidden="Yes"
fi
Expand Down
75 changes: 54 additions & 21 deletions restore.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

BR_VERSION="System Tar & Restore 3.9.2"
BR_VERSION="System Tar & Restore 3.9.3"

BR_EFI_DETECT_DIR="/sys/firmware/efi"
BR_SEP="::"
Expand All @@ -20,7 +20,6 @@ info_screen() {
echo -e "\n${BR_YELLOW}This script will restore a backup image of your system or transfer this\nsystem in user defined partitions."
echo -e "\n==>Make sure you have created one target root (/) partition. Optionally\n you can create or use any other partition (/boot /home /var etc)."
echo -e "\n==>Make sure that target LVM volume groups are activated and target\n RAID arrays are properly assembled."
echo -e "\n==>If the target system is Fedora (or variant), select bsdtar archiver.${BR_NORM}"
echo -e "\n${BR_CYAN}Press ENTER to continue.${BR_NORM}"
}

Expand Down Expand Up @@ -103,9 +102,9 @@ check_wget() {
rm /tmp/wget_error
rm /mnt/target/fullbackup 2>/dev/null
if [ "$BRinterface" = "cli" ]; then
echo -e "[${BR_RED}ERROR${BR_NORM}] Error downloading file. Wrong URL or network is down"
echo -e "[${BR_RED}ERROR${BR_NORM}] Error downloading file. Wrong URL, network is down or package wget is not installed."
elif [ "$BRinterface" = "dialog" ]; then
dialog --title "Error" --msgbox "Error downloading file. Wrong URL or network is down." 5 57
dialog --title "Error" --msgbox "Error downloading file. Wrong URL, network is down or package wget is not installed." 6 65
fi
else
if file /mnt/target/fullbackup | grep -w gzip > /dev/null; then
Expand Down Expand Up @@ -222,10 +221,12 @@ run_tar() {
BR_MAINOPTS="xvpfj"
fi

IFS=$DEFAULTIFS

if [ "$BRarchiver" = "tar" ]; then
$BRarchiver ${BR_MAINOPTS} /mnt/target/fullbackup -C /mnt/target && (echo "System decompressed successfully" >> /tmp/restore.log)
$BRarchiver ${BR_MAINOPTS} /mnt/target/fullbackup ${BR_USER_OPTS[@]} -C /mnt/target && (echo "System decompressed successfully" >> /tmp/restore.log)
elif [ "$BRarchiver" = "bsdtar" ]; then
$BRarchiver ${BR_MAINOPTS} /mnt/target/fullbackup -C /mnt/target 2>&1 && (echo "System decompressed successfully" >> /tmp/restore.log) || touch /tmp/r_error
$BRarchiver ${BR_MAINOPTS} /mnt/target/fullbackup ${BR_USER_OPTS[@]} -C /mnt/target 2>&1 && (echo "System decompressed successfully" >> /tmp/restore.log) || touch /tmp/r_error
fi
}

Expand Down Expand Up @@ -695,6 +696,9 @@ show_summary() {
if [ "$BRmode" = "Transfer" ]; then
echo -e "\n${BR_YELLOW}RSYNC OPTIONS:"
echo -e "${BR_RSYNCOPTS[@]}${BR_NORM}" | sed -r -e 's/\s+/\n/g' | sed 'N;s/\n/ /'
elif [ "$BRmode" = "Restore" ] && [ -n "$BR_USER_OPTS" ]; then
echo -e "\n${BR_YELLOW}ARCHIVER OPTIONS:"
echo -e "${BR_USER_OPTS[@]}${BR_NORM}" | sed -r -e 's/\s+/\n/g' | sed 'N;s/\n/ /'
fi
}

Expand Down Expand Up @@ -988,7 +992,7 @@ check_archive() {
if [ "$BRinterface" = "cli" ]; then
echo -e "[${BR_RED}ERROR${BR_NORM}] Error reading archive"
elif [ "$BRinterface" = "dialog" ]; then
dialog --title "Error" --msgbox "Error reading archive." 5 26
dialog --title "Error" --msgbox "Error reading archive.\n\n$(cat /tmp/filelist | grep -i ": " )" 0 0
fi
else
target_arch=$(grep -F 'target_architecture.' /tmp/filelist)
Expand Down Expand Up @@ -1149,7 +1153,11 @@ report_vars_log() {
fi
echo "Kernel Options: $BR_KERNEL_OPTS"
echo "Mode: $BRmode"
echo "Rsync Options: ${BR_RSYNCOPTS[@]}"
if [ "$BRmode" = "Restore" ]; then
echo "Archiver Options: ${BR_USER_OPTS[@]}"
elif [ "$BRmode" = "Transfer" ]; then
echo "Rsync Options: ${BR_RSYNCOPTS[@]}"
fi
echo "Distro: $BRdistro"
if [ "$BRmode" = "Restore" ]; then
echo "Architecture: ${target_arch#*.}"
Expand All @@ -1166,6 +1174,16 @@ report_vars_log() {
echo -e "\n${BR_SEP}TAR/RSYNC STATUS"
}

options_info() {
if [ "$BRarchiver" = "tar" ]; then
BRoptinfo="see tar --help"
elif [ "$BRarchiver" = "bsdtar" ]; then
BRoptinfo="see man bsdtar"
elif [ "$BRmode" = "Transfer" ]; then
BRoptinfo="see rsync --help"
fi
}

BRargs=`getopt -o "i:r:e:s:b:h:g:S:f:u:n:p:R:qtoU:Nm:k:c:a:O:v" -l "interface:,root:,esp:,swap:,boot:,home:,grub:,syslinux:,file:,url:,username:,password:,help,quiet,rootsubvolname:,transfer,only-hidden,user-options:,no-color,mount-options:,kernel-options:,custom-partitions:,archiver:,other-subvolumes:,verbose" -n "$1" -- "$@"`

if [ "$?" -ne "0" ];
Expand Down Expand Up @@ -1293,11 +1311,12 @@ while true; do
echo -e "
${BR_BOLD}$BR_VERSION
Interface:${BR_NORM}
General:${BR_NORM}
-i, --interface interface to use (cli dialog)
-N, --no-color disable colors
-q, --quiet dont ask, just run
-v, --verbose enable verbose tar/rsync output (cli only)
-U, --user-options additional tar/rsync options (see tar --help, man bsdtar or rsync --help)
${BR_BOLD}Restore Mode:${BR_NORM}
-f, --file backup file path or url
Expand All @@ -1309,7 +1328,6 @@ ${BR_BOLD}Restore Mode:${BR_NORM}
${BR_BOLD}Transfer Mode:${BR_NORM}
-t, --transfer activate transfer mode
-o, --only-hidden transfer /home's hidden files and folders only
-U, --user-options additional rsync options (see rsync --help)
${BR_BOLD}Partitions:${BR_NORM}
-r, --root target root partition
Expand Down Expand Up @@ -1784,11 +1802,16 @@ if [ "$BRinterface" = "cli" ]; then
echo -e "${BR_RED}Please select a valid option${BR_NORM}"
fi
done
fi
if [ -z "$BRuseroptions" ]; then
echo -e "\n${BR_CYAN}Enter additional rsync options (leave blank for defaults)${BR_NORM}"
read -p "Options (see rsync --help): " BR_USER_OPTS
options_info
if [ -z "$BRuseroptions" ]; then
echo -e "\n${BR_CYAN}Enter additional tar/rsync options (leave blank for defaults)${BR_NORM}"
if [ "$BRarchiver" = "tar" ]; then
echo -e "[${BR_CYAN}INFO${BR_NORM}] If the target system is Fedora 19+, you should add ${BR_YELLOW}--xattrs-include='*'${BR_NORM}"
fi
read -p "Options ($BRoptinfo): " BR_USER_OPTS
fi
check_input
Expand All @@ -1811,8 +1834,10 @@ if [ "$BRinterface" = "cli" ]; then
fi
if [ -f /mnt/target/fullbackup ]; then
($BRarchiver tf /mnt/target/fullbackup || touch /tmp/tar_error) | tee /tmp/filelist |
IFS=$DEFAULTIFS
($BRarchiver tf /mnt/target/fullbackup ${BR_USER_OPTS[@]} || touch /tmp/tar_error) | tee /tmp/filelist |
while read ln; do a=$(( a + 1 )) && echo -en "\rReading archive: $a Files "; done
IFS=$'\n'
check_archive
fi
Expand Down Expand Up @@ -1863,8 +1888,10 @@ if [ "$BRinterface" = "cli" ]; then
done
if [ -f /mnt/target/fullbackup ]; then
($BRarchiver tf /mnt/target/fullbackup || touch /tmp/tar_error) | tee /tmp/filelist |
IFS=$DEFAULTIFS
($BRarchiver tf /mnt/target/fullbackup ${BR_USER_OPTS[@]} || touch /tmp/tar_error) | tee /tmp/filelist |
while read ln; do a=$(( a + 1 )) && echo -en "\rReading archive: $a Files "; done
IFS=$'\n'
check_archive
fi
done
Expand Down Expand Up @@ -1990,7 +2017,7 @@ elif [ "$BRinterface" = "dialog" ]; then
unset BR_NORM BR_RED BR_GREEN BR_YELLOW BR_BLUE BR_MAGENTA BR_CYAN BR_BOLD
if [ -z "$BRrestore" ] && [ -z "$BRuri" ]; then
dialog --yes-label "Continue" --no-label "View Partition Table" --title "$BR_VERSION" --yesno "$(info_screen)" 17 80
dialog --yes-label "Continue" --no-label "View Partition Table" --title "$BR_VERSION" --yesno "$(info_screen)" 16 80
if [ "$?" = "1" ]; then
dialog --title "Partition Table" --msgbox "$(disk_report)" 0 0
fi
Expand Down Expand Up @@ -2202,10 +2229,12 @@ elif [ "$BRinterface" = "dialog" ]; then
BRhidden="y"
fi
fi
fi
if [ -z "$BRuseroptions" ]; then
BR_USER_OPTS=$(dialog --no-cancel --inputbox "Enter additional rsync options. Leave empty for defaults.\n(see rsync --help)" 8 70 2>&1 1>&3)
fi
options_info
if [ -z "$BRuseroptions" ]; then
BR_USER_OPTS=$(dialog --no-cancel --inputbox "Enter additional tar/rsync options. Leave empty for defaults.$(if [ "$BRarchiver" = "tar" ]; then echo " If the target system is Fedora 19+, you should add --xattrs-include='*'"; fi)\n($BRoptinfo)" 10 74 2>&1 1>&3)
fi
IFS=$'\n'
Expand Down Expand Up @@ -2235,8 +2264,10 @@ elif [ "$BRinterface" = "dialog" ]; then
fi
if [ -f /mnt/target/fullbackup ]; then
($BRarchiver tf /mnt/target/fullbackup 2>&1 || touch /tmp/tar_error) | tee /tmp/filelist |
IFS=$DEFAULTIFS
($BRarchiver tf /mnt/target/fullbackup ${BR_USER_OPTS[@]} 2>&1 || touch /tmp/tar_error) | tee /tmp/filelist |
while read ln; do a=$(( a + 1 )) && echo -en "\rReading archive: $a Files "; done | dialog --progressbox 3 40
IFS=$'\n'
sleep 1
check_archive
fi
Expand Down Expand Up @@ -2297,8 +2328,10 @@ elif [ "$BRinterface" = "dialog" ]; then
check_wget
fi
if [ -f /mnt/target/fullbackup ]; then
($BRarchiver tf /mnt/target/fullbackup 2>&1 || touch /tmp/tar_error) | tee /tmp/filelist |
IFS=$DEFAULTIFS
($BRarchiver tf /mnt/target/fullbackup ${BR_USER_OPTS[@]} 2>&1 || touch /tmp/tar_error) | tee /tmp/filelist |
while read ln; do a=$(( a + 1 )) && echo -en "\rReading archive: $a Files "; done | dialog --progressbox 3 40
IFS=$'\n'
sleep 1
check_archive
fi
Expand Down

0 comments on commit 13980cd

Please sign in to comment.