autorestic icon indicating copy to clipboard operation
autorestic copied to clipboard

Upgrade fails if `tmp` is on different filesystem

Open sebdanielsson opened this issue 2 years ago • 10 comments

Describe the bug autorestic upgrade fails with errors like:

  • os.Rename() failed (rename /tmp/autorestic-1252517049 /usr/local/bin/autorestic: invalid cross-device link), retrying with io.Copy()
  • Error: open /usr/local/bin/autorestic: text file busy.

Se detailed output below.

Expected behavior autorestic should upgrade itself.

Environment

  • OS: Fedora
  • Version: 35

Additional context

❯ autorestic upgrade --verbose
Using config paths: . /root /root/.config/autorestic
restic already installed
> Executing: /usr/bin/restic self-update
writing restic to /usr/bin/restic
find latest release of restic at GitHub
restic is up to date

Downloading: https://github.com/cupcakearmy/autorestic/releases/download/v1.7.1/autorestic_1.7.1_linux_amd64.bz2
os.Rename() failed (rename /tmp/autorestic-1252517049 /usr/local/bin/autorestic: invalid cross-device link), retrying with io.Copy()
Error: open /usr/local/bin/autorestic: text file busy
cannot lock before reading config location

sebdanielsson avatar Apr 27 '22 21:04 sebdanielsson

Can you reproduce it? Seemed fine to me on macos and linux

cupcakearmy avatar May 01 '22 16:05 cupcakearmy

You probably have /tmp on a different file system I suppose?

https://stackoverflow.com/a/42400063/2425183

cupcakearmy avatar May 01 '22 16:05 cupcakearmy

Not sure how to know. My fstab only contains an ext4 partition mounted at / and a swap partition.

sebdanielsson avatar May 01 '22 17:05 sebdanielsson

It might be on snorher file system. Both Fedora and Arch use tmpfs.

https://wiki.archlinux.org/title/tmpfs#Usage

"Arch uses a tmpfs /run directory, with /var/run and /var/lock simply existing as symlinks for compatibility. It is also used for /tmp by the default systemd setup and does not require an entry in fstab unless a specific configuration is needed."

Not sure how to check if this is true for me but after some googling I found out that Fedora has been using tmpfs since version 18.

sebdanielsson avatar May 01 '22 17:05 sebdanielsson

Just ran autorestic upgrade on my Manjaro machine and it said upgrade was successful but it basically just deleted itself. Trying to run the command again returns: command not found

sebdanielsson avatar May 01 '22 18:05 sebdanielsson

That sounds bad, definitely need to look at the upgrade function.

cupcakearmy avatar May 02 '22 07:05 cupcakearmy

Been playing around with datadog the last couple of days and discovered that Fedora is indeed using tmpfs so that is probably the issue☺️

sebdanielsson avatar May 29 '22 15:05 sebdanielsson

Hello, i faced to this issue today when i tried to upgrade autorestic to 1.7.2 version Is there any news on this issue ?


edit : 22/10/22

i write a little bash script it's not perfect but it do the job as a workaround until this is fixed

#!/bin/bash

currentBin="/usr/local/bin/autorestic"

# get latest tag release name
latest_vtag=$(curl --silent "https://api.github.com/repos/cupcakearmy/autorestic/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
latest_tag=${latest_vtag:1}

binUrl="https://github.com/cupcakearmy/autorestic/releases/download/v$latest_tag/autorestic_${latest_tag}_linux_amd64.bz2"
sha256SumsUrl="https://github.com/cupcakearmy/autorestic/releases/download/v$latest_tag/SHA256SUMS"

wget $binUrl --directory-prefix /tmp/
wget $sha256SumsUrl --directory-prefix /tmp/

cd /tmp || exit

sha256sum -c /tmp/SHA256SUMS --ignore-missing

if [ "$?" == 0 ]; then
	bzip2 -d ./autorestic_${latest_tag}_linux_amd64.bz2
	mv $currentBin /tmp/autorestic_old
	cp autorestic_${latest_tag}_linux_amd64 $currentBin
	chmod 755 /usr/local/bin/autorestic
fi

printf "autorestic successfully updated"
autorestic --version

exit 0

jee-r avatar Aug 25 '22 12:08 jee-r

TLDR; we need to copy and delete instead of renaming, otherwise it fails over different filesystems https://stackoverflow.com/a/42400063/2425183

cupcakearmy avatar Aug 25 '22 13:08 cupcakearmy

Hit this error today... is there any built-in workaround?

greyivy avatar Jan 22 '24 15:01 greyivy