Sorry I wasn’t able to respond sooner. Currently, I’m only ever able to attempt a backup on weekends. Wanted to update:
I love this approach. I’ll use it more on the new device but right now I’ll migrate what I need one by one (I don’t think I’ve messed with more than 2-3 files that I want to keep).
I’ve been able to go through with the back up, finally. I formatted the drive
sudo mkfs -t ext4 /dev/sdb1
Then, I had two problems overall. First was having spaces in the drive’s name which resulted in a confused script then kept creating these directories which I don’t need. I finally managed to overcome this by trial and error and going online. This is what I currently have that has worked:
#!/usr/bin/env sh
# Waits for input
read -p "Press enter to start the backup"
# Checks if you are root
if [[ $EUID == 0 ]]; then
echo "Yes Master! Working..."
else
MSG=("I am tired..." "I don't feel like it." "Not today..." "Please ask your dad. If he says no, then ask your mom." "You don't say the magic word :-P" "What came first? The hen or the egg?" "The author of the script will now be informed." "Damn... No way.")
NUMMSG=${#MSG[*]}
echo "${MSG[$((RANDOM%NUMMSG))]}"
exit 1
fi
SRC="/home/" # the slash / at the end is important
DST="$PWD/backup_home"
DATE=$(date +%Y-%m-%d-%H:%M:%S)
#if DST not there, then choose the current working dir.
if [[ ! -d "$DST" ]]; then
echo -e "$DST is not valid. Choosing $PWD/rsync_backup-$DATE instead."
DST="$PWD/rsync_backup-$DATE"
mkdir -p "$DST"
fi
# Add here pattern to exclude:
EX=(".cache*" ".thumbnails*" ".local/share/[Tt]rash" "*.backup*" "*~" ".dropbox*" "*tmp*" "*temp*" ".Private" "[aA]naconda3" "pycharm*" "idea*" "clion*" ".local/share/Steam")
if [[ "$SRC" == "/" ]]; then
#only relevant for full system backup:
EX+=("/media/*" "/sys/*" "/tmp/*" "/var/tmp/*" "/proc/*" "/swap/*" "/mnt/*" "/dev/*" "/run/*" "/etc/mtab" "/var/cache/pacman/pkg/*" "lost+found/*" "/var/backups/*" "*swapfile*")
fi
for x in ${EX[@]}; do
EXCLUDE+="--exclude=\"${x}\" "
done
VERBOSE=0
PROGRESS=2
LOG=1
QUIET=0
PARTIAL=0
TEMP=1
CHECKSUM=0
if [[ "$VERBOSE" == "1" ]]; then
OPTION+="--verbose "
fi
if [[ "$QUIET" == "1" ]]; then
OPTION+="--quiet "
fi
if [[ "$CHECKSUM" == "1" ]]; then
OPTION+="--checksum "
fi
if [[ "$PROGRESS" == "1" ]]; then
OPTION+="--progress "
elif [[ "$PROGRESS" == "2" ]]; then
# More information : rsync --info=help
OPTION+="--info=all0,progress2 "
fi
# Useful when syncing big files and abort it.
# It will continue at the state when it stopped.
if [[ "$PARTIAL" == "1" ]]; then
PARTDIR="$PWD/rsync_partial"
mkdir -p "$PARTDIR"
OPTION+="--partial --partial-dir=\"${PARTDIR}\" "
fi
#First copy files to temp and then move them in place
if [[ "$TEMP" == "1" ]]; then
TEMPDIR="$PWD/rsync_temp"
mkdir -p "$TEMPDIR"
OPTION+="--temp-dir=\"${TEMPDIR}\" --delay-updates "
fi
# Good for inspecting each backup process.
if [[ "$LOG" == "1" ]]; then
LOGFILE="$PWD/rsync_log-$DATE.txt"
touch "$LOGFILE"
OPTION+="--log-file=\"${LOGFILE}\" "
fi
echo "Backup has been started..."
if [[ "$LOG" == "1" ]]; then
echo "The log is saved here: $LOGFILE"
fi
COMMAND="rsync --archive --recursive --human-readable --safe-links --perms --times --atimes --open-noatime --group --owner --devices --specials --update --hard-links --executability --delete --delete-delay --delete-excluded --prune-empty-dirs $OPTION $EXCLUDE \"${SRC}\" \"${DST}\""
# display the rsync command for inspectation
# ./scriptname -v
if [[ "$1" == "-v" ]]; then
echo "$COMMAND"
elif [[ "$PROGRESS" == "2" ]]; then
echo -e "\nTotal Progress:\n"
eval "$COMMAND"
else
eval "$COMMAND"
fi
Basically, I’ve surrounded the filenames with double quotes.
I’ve also added some more exclude options.
The second problem was that right at the end it would fail to copy over some small config files from rsync_partial to backup_home (some seem to have been modified in the time period after being copied to partial but before being copied to backup) so I ended up not using the partial option which is only somewhat disappointing. Not using partial, I was able to easily complete the backup.
What’s cool is that now I (probably) can look at what files I have on my backup and rerun it with more exclude options and remove more useless configs. Though some configs must be useful (I’m just not sure which ones yet), I’m probably going to end up trying to restore this backup to the new machine and then deleting what I don’t need straight from there and rerun the backups then.
I will probably not try and back up the root partition after reading the answers in this thread but instead attempt to make a Timeshift backup on the new machine.
Now all that’s left is to run some more optional backups to get rid of more useless stuff and try and install Manjaro on the new machine and try a restore there. This should be interesting. I will keep this updated if I run into trouble during my restore (not getting rid of my old machine anyway just in case I need to back up again).
@megavolt @Fabby Thank you for your continuous help and, more importantly, understanding. There is still much for me to learn.