You are not logged in.

#1 2021-02-27 22:43:41

madrafa
Member
Registered: 2021-02-19
Posts: 11

rsync how to properly backup each destination file that it's replacing

I'm working on an script to easily install my dotfiles on a new machine. The basic functionality of installing all dependencies and my personal dotfiles is pretty much done. There's a few things that I'd like to add, like backing up each file that it's replacing on the new machine, because for now it just deletes/replaces the old files with the new ones.

I've struggling with rsync and the options --backup and backup-dir=DIR. Can get them to do the backup. Have tried a lot of different options but nothing.

Also I found this thread that pretty much describes my problem. But I just don't understand why it doesn't work, I'm doing like it says in that thread, the path points to the destination side.

This is the script right now:

#!/bin/bash

user_does() {
    repo="https://github.com/user/dotfiles.git"
    git_dir=".dotfiles"
    dir_tmp=$(mktemp -d)

    # clone repository
    git clone --recurse-submodules --separate-git-dir="$HOME"/$git_dir $repo "$dir_tmp" ;

    # copy all dotfiles to $HOME (this will overwrite any existing destination file)
    # can't get backup options to work :( 
    rsync --backup --backup-dir="$HOME"/backups --recursive --exclude '.git' "$dir_tmp"/ "$HOME"/ ;
    rm --force --recursive "$dir_tmp" ;

    # git set-up for dotfiles
    function dot {
       /usr/bin/git --git-dir="$HOME"/$git_dir/ --work-tree="$HOME" "$@"
    }
    dot config status.showUntrackedFiles no

    # junegunn/vim-plug for managin plugins
    sh -c 'curl -fLo "${XDG_DATA_HOME:-$HOME/.local/share}"/nvim/site/autoload/plug.vim --create-dirs \
        https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'

    # install neovim's plugins
    nvim --headless +PlugInstall +qall
}
user_does

Also tried giving a full path to

backup-dir

like this

backup-dir=/home/user/backups

but that doesn't work either. I've tried other things like changing the order of the options, but again... nothing.

So after like two weeks trying to make this work in my free time, and failing. I'm asking for help.

What should be the proper way of doing this ? what I'm I missing ?

Offline

Board footer

Powered by FluxBB