Linuxgsm: realpath not found / wrong arguments when attempting backup on debian/ubuntu systems

Created on 8 Dec 2017  路  9Comments  路  Source: GameServerManagers/LinuxGSM

Backup appears to be broken on ubuntu/debian systems, because realpath is not shipped with the coreutils on deb/ubuntu: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=693211.

There is a separate 'realpath' package, but that version doesn't appear to support the --relative-to argument.

This appears to be caused by this PR: #1676 , which is a fix for this bug: #1563

Perhaps the usage of realpath could be replaced by readlink -f somehow?

steam@devi:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 14.04.5 LTS
Release:        14.04
Codename:       trusty
steam@devi:~$ ./sdtdserver backup
    fetching command_backup.sh...OK
[  OK  ] Backup sdtdserver: Backup starting
[ INFO ] Backup sdtdserver: There are no previous backups
[ .... ] Backup sdtdserver: Backup (3.3G) sdtdserver-2017-12-08-000441.tar.gz, in progress.../home/steam/lgsm/functions/command_backup.sh: line 115: realpath: command not found
tar: ./lgsm/backup/sdtdserver-2017-12-08-000441.tar.gz: file changed as we read it
FAIL
[ FAIL ] Backup sdtdserver: Starting backup
steam@devi:~$ realpath
The program 'realpath' is currently not installed. To run 'realpath' please ask your administrator to install the package 'realpath'
root@devi:~# apt install realpath
[snip]
steam@devi:~$ dpkg -l realpath
[snip]
ii  realpath                              1.19                    amd64                   Return the canonicalized absolute pathname
steam@devi:~$ ./sdtdserver backup
[  OK  ] Backup sdtdserver: Backup starting
        * Previous backup was created less than 1 day ago, total size 4.5G
[ WARN ] Backup sdtdserver: sdtdserver will be stopped during the backup
[  OK  ] Stopping sdtdserver: Graceful: telnet: 127.0.0.1: OK
[  OK  ] Stopping sdtdserver: devi
[ .... ] Backup sdtdserver: Backup (3.3G) sdtdserver-2017-12-08-013330.tar.gz, in progress...realpath: unrecognized option '--relative-to=/home/steam'
Usage:
 realpath [-s|--strip] [-z|--zero] filename ...
 realpath -h|--help
 realpath -v|--version
backup bug

Most helpful comment

I need to do more thorough error handling, but you can try this as a command_backup.sh replacement.

Report back your findings and I'll work on error handling/cleanups in preparation for a PR.

All 9 comments

I'm somewhat confident that I could fix this but the issue definitely relies with making realpath a required dependency, and editing the usage of realpath in the lgsm/functions/command_backup.sh.

The error I get is from line 115 saying this:

fraghaven1@fraghaven1:~$ ./csgoserver backup
fetching command_backup.sh...OK
[ OK ] Backup csgoserver: Backup starting
[ INFO ] Backup csgoserver: There are no previous backups
[ .... ] Backup csgoserver: Backup (18G) csgoserver-2017-12-14-053741.tar.gz, in progress.../home/fraghaven1/lgsm/functions/command_backup.sh: line 115: realpath: command not found
tar: ./lgsm/backup/csgoserver-2017-12-14-053741.tar.gz: file changed as we read it

Edit: After installing realpath, I get these errors (looks like we are in the same boat):

fraghaven1@fraghaven1:~$ ./csgoserver backup
[ OK ] Backup csgoserver: Backup starting
[ INFO ] Backup csgoserver: There are no previous backups
[ .... ] Backup csgoserver: Backup (18G) csgoserver-2017-12-14-064806.tar.gz, in progress...realpath: unrecognized option '--relative-to=/home/fraghaven1'
Usage:
realpath [-s|--strip] [-z|--zero] filename ...
realpath -h|--help
realpath -v|--version
tar: ./lgsm/backup/csgoserver-2017-12-14-064806.tar.gz: file changed as we read it

If you've happened to find a fix for this, please let me know so I can submit a pull request.

function relpath() {    python -c "import os,sys;print(os.path.relpath(*(sys.argv[1:])))" "$@"; }
steam@devi:~/lgsm/functions$ relpath $(readlink -f ../../lgsm/) /home/steam
lgsm

I think this will do the same thing, if you don't mind the python dep.

(from https://stackoverflow.com/a/31236568/499571)

function cedar-realpath() {
  # Written by CedarLUG as a realpath alternative in bash
  declare -a rdirtoks=($(readlink -f "${rootdir}" | sed "s/\// /g"))
  declare -a bdirtoks=($(readlink -f "${backupdir}" | sed "s/\// /g"))

  for ((base=0; $base<${#rdirtoks[@]}; base++))
  do
      [[ "${rdirtoks[$base]}" != "${bdirtoks[$base]}" ]] && break
  done

  for ((x=${base};$x<${#rdirtoks[@]};x++))
  do
      echo -n "../"
  done

  for ((x=${base};$x<$(( ${#bdirtoks[@]} - 1 ));x++))
  do
      echo -n "${bdirtoks[$x]}/"
  done

  if (( "$base" < "${#bdirtoks[@]}" )) 
  then
      echo ${bdirtoks[ $(( ${#bdirtoks[@]} - 1)) ]}
  else
      echo
  fi
}

Anything to avoid the havoc caused by python dependencies. The above function seems to do what you need in lieu of realpath. It swaps the realpath dependency for readlink, which is already in coreutils.

Here's sample output:

cedarlug@dhs-scanner:~$ rootdir=/tmp backupdir=/usr/local cedar-realpath 
../usr/local
cedarlug@dhs-scanner:~$ realpath --relative-to=/tmp /usr/local
../usr/local
cedarlug@dhs-scanner:~$ mkdir -p foo/bar/a/b/c
cedarlug@dhs-scanner:~$ mkdir -p foo/1/2/3
cedarlug@dhs-scanner:~$ cd foo/bar/
cedarlug@dhs-scanner:~/foo/bar$ pwd
/home/cedarlug/foo/bar
cedarlug@dhs-scanner:~/foo/bar$ backupdir=../1/2/ rootdir=a/b/c/ cedar-realpath 
../../../../1/2
cedarlug@dhs-scanner:~/foo/bar$ realpath --relative-to=a/b/c ../1/2
../../../../1/2

Updated: show consistency with realpath.

I need to do more thorough error handling, but you can try this as a command_backup.sh replacement.

Report back your findings and I'll work on error handling/cleanups in preparation for a PR.

cedarlug, i have same problem on Ubuntu 14.04 LTS
your script works correctly, thx :)

Hi,

I hit the same bug as @smw too, same OS. Installing realpath package also resulted in unsupported flag.

@cedarlug command_backup.sh replacement did the trick.

BR
Draakuns

A fix from cedarlug is on its way ;)

Any update on this? @cedarlug

My assertion is that a simple mkdir -p {$backupdir} prior to the relpath bash script replacement that was composed for the fix addresses everything and that the PR that was made solves the issue.

I was unable to confirm because of the issues with travis, and stopped banging my head against the wall when it became clear that there was more pain being inflicted on my head than on travis.

#1727 #1839

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MicLieg picture MicLieg  路  3Comments

UltimateByte picture UltimateByte  路  4Comments

borzaka picture borzaka  路  3Comments

dj-hyb picture dj-hyb  路  3Comments

BarbieQ1 picture BarbieQ1  路  4Comments