Backing up recommendations

Hello, everyone. I was thinking of switching over to a new laptop in the near future but I’m basically held captive until I manage to perform a backup I’m confident I know how to restore from which I have delayed up to this point.
I’ve gone over
https://forum.manjaro.org/t/howto-make-a-crash-proof-backup-for-manjaro/3970 and some others but I feel like I need to hear some tips first that match my particular scenario since I’m naturally anxious when it comes to my files and I don’t want to screw this up or back up in a way I might regret later.
I have a Seagate expansion drive that’s got a few files I’ve put there just to test.
I have a dual boot of Windows 10 and Manjaro.
I’d like to make a backup of my system with the following considerations:

  • I want to back up folders of my Windows partition, say my Documents and Desktop folders, among others. I have access to this partition in my file manager on Manjaro and that is usually how I access them daily (I don’t usually boot into Windows). I want to keep them all in a separate folder from the Manjaro backup on the external storage device.
  • I’d like to back up my Manjaro system in such a way that the files are copied as-is to the expansion drive so I can view them there later (I’ve seen that quite a few solutions make compressed backups that can’t be viewed). Is doing it the way I’m suggesting considered good practice?
  • I’d like subsequent backups to only update what’s changed since the last backup.
  • What I’d really like is if there was a way for me to back up my files, apps and their configurations or at least to have a way of quickly installing the software I had on the new machine too. I have a /, /home and /boot partitions.

I’ve had an unsuccessful run with rsync a while ago and I haven’t tried again since. I don’t remember the options I gave for the command. The problem, as I remember, was a .cache directory inside of my home directory that was too big and changed too often. I understand I shouldn’t try to back it up. What should I back up and what not from my root and home partitions in order to get all date needed to restore the apps and configurations?
Also, should I format my expansion drive to ext4 for this or should it stay at NTFS?

I know some of this is somewhat vague, so if you could help me clear only some of my doubts I would be very grateful.

Thanks.

ok I try to give some tips:

  1. Separate backups for your system and home.
  2. Timeshift is a good tool for just backup and restore the system without touching home. It is used equivalently to “system recovery” from Windows.
  3. If you need just one copy on the HDD of your files on home… just run it with rsync:
sudo rsync \
 --recursive \
--links \
--perms \
--times \
--group \
--owner \
--devices \
--specials \
--update \
--hard-links \
--checksum \
--executability \
/home/ /path/to/external/hdd/backup_home

or in short:

sudo rsync -aucHE /home/ /path/to/external/hdd/backup_home

It copies, updates and preserves pretty everything recursively.

Just put the script on the external HDD and run it when connected. This should work:

#!/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="/path/to/external/hdd/backup_home"

#if DST not there, then choose the current working dir. 
if [[ ! -d $DST ]]; then
    echo -e "$DST is not valid. Choosing $PWD instead."
    DATE=$(date +%Y-%m-%d-%H:%M:%S)
    DST="$PWD/backup-$DATE"
    mkdir -p $DST
fi

# runs the backup
rsync \
--recursive \
--links \
--perms \
--times \
--group \
--owner \
--devices \
--specials \
--update \
--hard-links \
--checksum \
--executability \
--delete-delay \
--exclude="*cache*" \
--exclude="*temp*"  \
--exclude="*tmp*"  \
--exclude="*~"  \
$SRC $DST

:warning: IT HAVE TO BE A LINUX FILESYSTEM, NTFS WILL NOT WORK.

Yes, to backup correctly you need ext4 or another linux filesystem if you want them viewable and searchable on the disk. NTFS is not compatible with the ACL of linux.

If the destination is a linux file system, then you can run the exact same command. NTFS can not be used as destination.

2 Likes

Thank you very much. I’ll have the chance to give the script a test run in a few days and update on the results.

O.K., I will also try and format the expansion drive to ext4.

So I understand from the tutorials I’ve seen that this can help you back up the root partition and then, for home, you’re going to want go with rsync. Right? This would help clear things up. I will look into it as well.

If anyone has any other suggestions or files you think I shouldn’t be backing up, I would love to hear it.
I will keep you informed about the results.

1 Like

I updated the script so that it have some additional features… I think it is better this way:

#!/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="/media/backup/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")

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=1
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"
  OPTION+="--log-file=$LOGFILE "
fi

echo "Backup has been started..."

if [[ "$LOG" == "1" ]]; then 
  echo "The log is saved here: $LOGFILE"
fi

COMMAND="rsync --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"
  $COMMAND
else
  $COMMAND
fi
2 Likes

If you switch over to new hardware, please be aware that you:

  • have to should reinstall the OS and any applications
  • you can selectively restore your home after installing all applications
  • You can restore any other data as a last step and that can include NTFS partitions.

I’ve restored Borg data backups on Manjaro from Ubuntu (just not the entire home directory as I switched to KDE, so I did a selective restore)…

System backups as per the article you looked at are for restoring on the same system only!

:man_shrugging:

Thank you but I’m not sure I fully understand. What I understand from this is that first I have to install Manjaro on the new machine, install all the apps I’ve had and only then run a restore to my root partition (using Timeshift for instance if it was used to back up)?

I was under the impression that restoring the root partition allows me to skip installing the apps over again (for instance, if you run restore from a live CD after setting up the partitions on the disk but without installing Manjaro - can/should this be done?)

Also, if I need to install all applications before restoring, I need a list of applications currently installed - can it be possible that an app installed as an appimage/flatpak/executable or script of some kind/etc write some data to the root partition and therefore needs to also be installed besides the package manager apps?

In short: Can I just Install Manjaro, install Timeshift, connect my external drive, restore and get my apps back?

Yes thats correct. Maybe “installing” or “restoring” is the wrong term. Better: “write application data to disk”.
So:

  1. Without a system backup, you will have to install apps
  2. With a system backup, you can restore the apps.

Selectively restore config files at /home if you switching the Distro or the DE or the version has been changed, since it could cause trouble.

It depends and you might get lucky, but that’s not a guaranteed way to make it work.
I.E. If your old system has an old nVidia card using bumblebee and your new system contains an nVidia card not supported by Bumblebee, your system will not start the GUI and why I said:

But you might get lucky if you use well-behaved hardware 100% Linux kernel-compatible on both the old and the new system and then you don’t need to re-install anything and can just do a full system restore and don’t reinstall anything

  • No one can answer that for you. Be prepared to reinstall / and only restore /home.
  • I’m the author of the backup article you referred to so I use CloneZilla / Borg, not TimeShift for a reason

:man_shrugging:

I see. So there is no simple solution when it comes to backing up the root partition when switching machines. Even with CloneZilla.

So I need to keep a list of installed apps on the previous machine. So I can reinstall one by one manually to be sure, is that correct?

What if I have, for instance, a setting in my grub config that is not there by default on a fresh install or a custom hook running every software update or some other configuration in a file on my root partition that I’m not even aware of anymore? If restoring the root partition on the new system and not running into trouble has something to do with luck then what should I do about all those configurations that are saved there and not on the home partition?

What do you mean by ‘selectively’ restoring home?

Thank you very much for taking the time to answer this. I’m very happy Manjaro has just worked so far. That’s why I’m keen on having it on the new machine too.

That is why when I change a setting in a file, I do it this way:

cat /etc/sysctl.d/30-swap_usage.conf
# Fabby: 2014-03-02: change "swappiness" from default 60 to 10:
#  Theoretically, only swap when RAM usage reaches around 80 or 90 percent
# Fabby: 2014-03-29: lower to 5 as swapping is still occurring with low mem usage
# Fabby: 2014-11-21: Bring back up to 10 as vm.vfs_cache_pressure was introduced
vm.swappiness = 10

# Fabby: 2014-11-29: Lower vm.vfs_cache_pressure to 75%
# (once cached, probably not immediately needed any more)
#
#
# This value used to be a percentage value that controls the tendency of
# the kernel to reclaim the memory which is used for caching of directory and
# inode objects.
#
# At the default value of vfs_cache_pressure=100 the kernel will attempt to
# reclaim dentries and inodes at a "fair" rate with respect to pagecache and
# swapcache reclaim.  Decreasing vfs_cache_pressure causes the kernel to prefer
# to retain dentry and inode caches.
# Edit 2020: Nowadays the value can be >100!
vm.vfs_cache_pressure = 75

so if I reinstall, I just grep --files-with-matches --recursive Fabby /etc/* 2> /dev/null and out come all the files I have to move to the new system:

/etc/bash.bashrc
/etc/environment
/etc/fstab
/etc/hosts
/etc/inputrc
/etc/machine-info
/etc/systemd/system/boot_sound.service

Meaning: I only restore documents, pictures, Thunderbird, Firefox profile, … but not Firefox cache, teams cache, Wesnoth cache, Thumbnail cache, old save files from games, … (they are excluded from my backup anyway; no sense backing up what you won’t restore)

:+1:

1 Like

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.

That is a really bad idea if that’s on the same disk as your /home and the only thing I can tell you then is:

Make a cold off-line system backup

:man_shrugging:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.