11/05/2021

Backup-script using cronjob and rsync when external disk is connected

original blog (german) 

original script

The original script  worked partial for me! I missed notifications though. No idea why! The original script works in Debian.

 

First place the backup script in /root.

On Arch Linux make sure libnotify is installed and cronie.service is enabled:

$ sudo pacman -S libnotify

$ sudo systemctl enable cronie.service

$ sudo systemctl start cronie.service  


Get the external disk UUID:

$ ls -l /dev/disk/by-uuid

respectively

$ sudo blkid /dev/sdX

change sdX with your disk.  

 

Get your userid:

$ id -u <username>

 

Do a new cronjob:

$ sudo crontab -e

Fill in:

*/1 * * * * /root/backup.sh >> /dev/null 2>&1

Like this the script  is called every minute by cron.


This is my changed script:

Replace UUID, <yourusername> and <youruserid>!

Be careful! The script will sync source-directory with destination-directory. Non existing files in source-directory will be deleted from destination-directory!

The script below will only do a testrun - change rsync options from -avn to -av


________________________________________________________________________________

#!/bin/bash
#holzboa
#Use at your own risk!


########## Konfiguration ############ 
UUID="d2428c4a-1a0b-4f1a-97eb-582b2b1adb94" #replace with you external disk UUID
CHECK_DISC="/dev/disk/by-uuid/$UUID"
DATE=`/bin/date +%Y%m%d`
CHECK_DATE_DIR="/root" #date-file directory and temporary mount backup-disk
BACKUP_DIR_MEDIA="backup" #here the backup-disk will be mounted temporary
BACKUP_DIR="$CHECK_DATE_DIR/$BACKUP_DIR_MEDIA" #backup directory, in this case root of backup disk
DATE_FILE="$CHECK_DATE_DIR/$DATE.date" #date-file, shows if backup was already done
CHECK_RSYNC=`ps -aef | grep -v grep | grep rsync | wc -l`
CHECK_MOUNT=`df -h | awk '{print $6}' | grep $BACKUP_DIR_MEDIA | wc -l`
SOURCE_DIR="/directory/to/save /other/directory/to/save /next/directory/to/save" # if you put a / in the end of path only the files inside the directory get saved

#####################################

/bin/umount $CHECK_DISC

if [ ! -d $CHECK_DATE_DIR/$BACKUP_DIR_MEDIA ]; then
    /bin/mkdir $CHECK_DATE_DIR/$BACKUP_DIR_MEDIA
fi

if [ $CHECK_RSYNC = 0 ]; then #if no other rsync-process is running, start it up
    if [ -e $CHECK_DISC ]; then
        if [ $CHECK_MOUNT = 0 ]; then
            if [ ! -f $DATE_FILE ]; then
                /bin/mount UUID=$UUID $CHECK_DATE_DIR/$BACKUP_DIR_MEDIA
                sleep 5
                rm -f $CHECK_DATE_DIR/*.date
                sudo -u <yourusername> DISPLAY=:0 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/<youruserid>/bus notify-send "backup-disk detectet" "start\ backup\ \(You\ will\ recieve\ a\ message\ after\ finishing\!\)"
                /usr/bin/rsync -avn --safe-links --delete --ignore-errors $SOURCE_DIR $BACKUP_DIR #only does a testrun. To do your backup change -avn to -av
                /bin/sync
                /usr/bin/touch $DATE_FILE
                /bin/umount /dev/disk/by-uuid/$UUID
            else
                sudo -u <yourusername> DISPLAY=:0 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/<youruserid>/bus notify-send "Backup already done today" "You\ may\ plug\ out\ the\ disk\ now\!"
            fi
        fi
    fi
fi

10/23/2020

feh autoscale

Open an image in feh, automatically scaling it to its window's size

$ feh --scale-down --auto-zoom

8/13/2020

ST (Simple Terminal - Suckless) install error



To compile st this will probably help:

$ sudo apt install libxft-dev libx11-dev


First try ended with errors:

x.c:11:10: fatal error: X11/Xatom.h:
x.c:15:10: fatal error: X11/Xft/Xft.h:


After installing these packets compiling worked like a charm.

6/08/2020

xfce4 - whisker menu - super left - xcape ksuperkey - arm

To use the left win buton to open Whisker Menu in XFCE4 and for keyboard shortcuts.


In keyboard settings change Alt+F1 to "xfce4-popup-whiskermenu"


With ksuperkey (wrapper for xcape):

yay -S ksuperkey


put in autostart:

ksuperkey


For arm ksuperkey is not available,
so take xcape:
 

sudo pacman -S xcape


put in autostart:
 

xcape -e 'Super_L=Alt_L|F1'




4/03/2020

BSD fzf ranger

I use the way described here:

Find and Locate using Fuzzy Finder (fzf)


But there is no mlocate package installable in BSD!


To use mlocate in BSD:

mlocate gets weekly updated as shown in /etc/defaults/periodic.conf
  weekly_locate_enable="YES"



To rebuild locate database:

# /etc/periodic/weekly/310.locate

2/08/2020

Ranger - The file manager - cli

Is like handling "Finder" in OSX, just much better!

Works great in st (sterm, stterm) and in urxvt.
I encountered some problems in xfce4-terminal and konsole with previewing images - some image fragments stay. 

Update: previewing images works well with ueberzug instead of w3m.

For people that are used to work with vim it will be easy to use ranger.

It previews all sort of files, plays them as well, opens files in x-apps ...











there are lot of possibilities to extend and configure ranger, for example search with fzf:

https://github.com/gotbletu/shownotes/blob/master/ranger_file_locate_fzf.md

or

https://github.com/alexanderjeurissen/ranger_devicons 

that brings nerdfonts to ranger





For those who own .dsf-files (SACD), ranger can preview them with mediainfo and play with mpv (where you can specify a certain audio output in ranger's config files).

I experienced some problems with the yank-commands in ranger so make sure you got xsel or xclip installed.

 

Quick start:

Ranger is available in your repositories so just install it with your favourite software manager (check dependencies and recommendations!).
then open up a terminal (CTRL+ALT+T) and do:

    $ ranger --copy-config all
    $ cd ~/.config/ranger
    $ ls

Now you see all your config files.

commands.py    -    here go commands like fzf, compress
 

rc.conf               -    here you do basic configuration like color, borders, preview, shortcuts
 

rifle.conf            -    specify the software used to open files
 

scope.sh            -    how you preview files

 

Once you did:

$ ranger 

type in ? to get a overview about commands, key-bindings, man-page and settings



Now in ranger press Tab so you can see invisible files, go to /.config/ranger (middle column is the one you're in), press m, then r - et voila, got you first bookmark.
To call bookmarks press ' and choose the letter you gave it before. You'll get a menu for that.

Moving is easy - cursor keys or, typical for the "vi-world" use hjkl


preview a file    -    press i
open a file        -    press right or enter
on a directory press dc    -    shows total foldersize

MediathekView - get the AppImage

After some troubles running Mediathekview i got the AppImage

https://download.mediathekview.de/stabil/MediathekView-latest-linux.AppImage

and made it work with ORF

https://forum.mediathekview.de/topic/1602/probleme-beim-download-und-abspielen-von-orf-sendungen/4

Problems solved! 

2/03/2020

Linux - autofs nfs



To get easy access to nfs shared folders install autofs:

Server:

    $ sudo pacman -S nfs-utils

Edit /etc/exports to add a share:

in a new line type something like

/folder/to/share   192.168.1.0/24(async,rw,no_subtree_check)

or extended like:

/srv/nfs 192.168.1.0/24(rw,sync,crossmnt,fsid=0)

/srv/nfs/music 192.168.1.0/24(rw,sync)

/srv/nfs/home 192.168.1.0/24(rw,sync,nohide)

when finished do:

$ systemctl enable nfs-server.service
$ systemctl start nfs-server.service

 

 

Client:

    $ sudo pacman -S autofs nfs-utils

Edit /etc/autofs/auto.master (Arch Linux) - otherwise it's /etc/auto.master:

$ sudo nano /etc/autofs/auto.master

look for the line starting with 

#net

make it:

/net -hosts --timeout=60

 


Note on /net and /smb:

These two default configurations may be useful for your set-up.
If you have a lot of NFS or Samba shares, you may want to uncomment these lines. /net enables auto-mounting of file systems elsewhere on the network which are exported by NFS.
For example, if you have a server named fileserver with an NFS export directory called /export, you can mount it by typing in a shell command line cd /net/fileserver/export.
In an environment with NFS file servers, such a configuration can be useful.
/smb functions the same way but is for Samba file systems.
However, if you need to authenticate before accessing the Samba share, automount will not function.


After do :

$ systemctl enable autofs.service
$ systemctl start autofs.service

To lookup nfs-shares:
$ showmount -e 192.168.1.xxx

Then connent from your remote client like (after IP auto-completion should work):
$ ls /net/192.168.1.xxx/my/share/like/in/output/of/showmount
If there appears the message
 clnt_create: RPC: Program not registered
 probably the nfs-server is inactive or there's something wrong with the exports.
$ systemctl status nfs-server.service
$ systemctl restart nfs-server.service

Just a few days ago I tried to install a nfs-server on Zyxel NSA325v2/ 4.4.271-1-ARCH-armv5tel
but the latest version of nfs-utils was not working and I had to downgrade. Thanks to http://tardis.tiny-vps.com/aarm/ that isn't a big deal


If shutown or reboot system takes a long time:

automount might be a problem.


/etc/systemd/system.conf

or

/etc/systemd/system/multi-user.target.wants/autofs.service 

has a line:

#DefaultTimeoutStopSec=90s

or

#TimeoutSec=180

which can be uncommented and changed!

TLP can cause waiting time as well!

 

 

Numlock Plasma Desktop

After startup Feren OS (my favourite at time) numlock  was still on. As i use a Raspberry keyboard (79 keys) that's pretty annoying.

Look for login settings

enter image description here


but changing here didn't solve my problem, though it's good to have numlock activatet by default just in case you need to scroll a tty output. 
The second to look for (what solved my problem) is keyboard settings.


2/02/2020

Linux - lsDeluxe - lsd

If you are on the command line listing directories and want to get fancy icons, lsd is the tool to use.


Not in the apt repositories, snap doesn't work for me so i went here: https://github.com/Peltoche/lsd/releases, downloaded the suitable .deb file.

Project's page

https://github.com/Peltoche/lsd


In Arch lsd is available in the repositories:
$ sudo pacman -S lsd

I had some problems with fonts - i ended up installing from https://github.com/ryanoasis/nerd-fonts/find/master:


patched-fonts/Hack/Regular/complete/Hack Regular Nerd Font Complete.ttf

 

 

Linux - fzf - command-line fuzzy finder

I tried to install fzf via apt but it seems it's not available in the repositories any more.
So i installed the snap version but that didn't work out as well. Snap listed the installed file but didn't start it.
My third choice was
$ git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf/install
That worked out for me.

On Deepin 15.11 i additionally had to run:
        $ source ~/.fzf.bash
to make it work.

Project's page:
https://github.com/junegunn/fzf

Use with ranger:
https://github.com/gotbletu/shownotes/blob/master/ranger_file_locate_fzf.md



A explaining video:




1/05/2020

tty change font size arch / debian

In Arch Linux:

ls -l /usr/share/kbd/consolefonts/ | grep -i ".ter-v32b.gz"

To list all available fonts, you can do:
fc-list

And search for a font with:
fc-list | grep -i "font name"
sudo pacman -S terminus-font
You'll get lot of new fonts added to /usr/share/kbd/consolefonts.
I wanted to get bigger fonts in tty as my screen is distant.
So i did
sudo nano /etc/vconsole.conf
to add
FONT=ter-v32b
svae the file with "Ctrl+o" and exit with "Ctrl+x".
After a reboot i got the right font but my keymapping in tty was overwritten so i did
 sudo localectl --no-convert set-keymap de-latin1-nodeadkeys
and i got the german keyboard layout in tty back.


In Debian:

sudo dpkg-reconfigure console-setup

12/04/2019

ZYXEL NSA 325v2 - nfs-shares

I added nfs shares via the Web-GUI and realized the nfs-shares show up but there are no folders or files at all though the free space is recognized.

so i did:
$ showmount -e 192.168.0.53 (#that's my NAS-Server IP-Adress)
/i-data/9e799388/nfs/photo  *
/i-data/9e799388/nfs/music  *
/i-data/9e799388/nfs/admin  *
/i-data/9e799388/nfs/public *
So the shared folders are in a nfs folder newly created and they are all empty. I wanted to share already existing folders.

so i did:
$ ssh admin@192.168.0.53
moved to:
$ cd /etc/idata/9e799388
There are all the folders where data is stored on the NAS and the newly created nfs-folder with my nfs-shares.
$ ls
admin        lost+found   nfs          photo        sysvol
aquota.user  music        opt          public       video
I want to share the folders admin, music, photo and pulic.
So via ssh i open:
$ export TERM=xterm
$ sudo nano /etc/exports

/i-data/9e799388/nfs/photo  *
/i-data/9e799388/nfs/music  *
/i-data/9e799388/nfs/admin  *
/i-data/9e799388/nfs/public *
 Just cut the /nfs, save the file wth strg+o and exit with strg+x.
 Then do:
$ sudo exportfs -ra
Exit the ssh-session and do again:
$ showmount -e 192.168.0.53
/i-data/9e799388/photo  *
/i-data/9e799388/music  *
/i-data/9e799388/admin  *
/i-data/9e799388/public *

After that all the stored files show up after do something like:
$ sudo mount -t nfs 192.168.0.53:/i-data/9e799388/photo /folder/where/you/want/to/mount



11/13/2019

linux toggle audio out

to find out about sinks:
$ pacmd list-sinks

to change sinks:
$ pacmd set-default-sink indexnumber

script to toggle:
#!/bin/bash 

new_sink=$(pacmd list-sinks | grep index | tee /dev/stdout | grep -m1 -A1 "* index" | tail -1 | cut -c12-)

echo "Setting default sink to: $new_sink";
pacmd set-default-sink $new_sink
pacmd list-sink-inputs | grep index | while read line
do
echo "Moving input: ";
echo $line | cut -f2 -d' ';
echo "to sink: $new_sink";
pacmd move-sink-input `echo $line | cut -f2 -d' '` $new_sink

done

 

11/09/2019

mpv show playlist keyboard shortcut



open ~/.config/mpv/input.conf with your favorite texteditor

add a shortcut:

shows playlist (bigger fonts than OSC):
ctrl+p show-text "${playlist}"

this displays the playlist the way the OSC does:
ctrl+p script-message osc-playlist

11/03/2019

thunar customized action: play dsf-audio with mpv

I wanded to do a customized Action in Thunar to play dsf files from a folder.

Name: dsf
Command: mpv %f --force-window
File pattern: *
Appears if selection contains: Directories, Other Files



to play it via my FIIO X5 (24bit/192kHz), Volume via mpv:

Name: fiiodsf
Command: mpv %f --force-window --audio-device=alsa/front:CARD=DAC,DEV=0
File pattern: *
Appears if selection contains: Directories, Other Files


to determine audio device:

$ mpv --audio-device=help

List of detected audio devices:
  'auto' (Autoselect device)
  'pulse/alsa_output.usb-SmartAction_FiiO_USB_Audio_Class_2.0_DAC_0007-01.analog-stereo' (FiiO USB Audio Class 2.0 DAC Analog Stereo)
  'pulse/alsa_output.pci-0000_00_03.0.hdmi-stereo' (Internes Audio Digital Stereo (HDMI))
  'alsa' (Default (alsa))
  'alsa/jack' (JACK Audio Connection Kit)
  'alsa/hdmi:CARD=HDMI,DEV=0' (HDA Intel HDMI, HDMI 0/HDMI Audio Output)
  'alsa/hdmi:CARD=HDMI,DEV=1' (HDA Intel HDMI, HDMI 1/HDMI Audio Output)
  'alsa/hdmi:CARD=HDMI,DEV=2' (HDA Intel HDMI, HDMI 2/HDMI Audio Output)
  'alsa/hdmi:CARD=HDMI,DEV=3' (HDA Intel HDMI, HDMI 3/HDMI Audio Output)
  'alsa/hdmi:CARD=HDMI,DEV=4' (HDA Intel HDMI, HDMI 4/HDMI Audio Output)
  'alsa/usbstream:CARD=HDMI' (HDA Intel HDMI/USB Stream Output)
  'alsa/sysdefault:CARD=PCH' (HDA Intel PCH, ALC892 Analog/Default Audio Device)
  'alsa/front:CARD=PCH,DEV=0' (HDA Intel PCH, ALC892 Analog/Front speakers)
  'alsa/surround21:CARD=PCH,DEV=0' (HDA Intel PCH, ALC892 Analog/2.1 Surround output to Front and Subwoofer speakers)
  'alsa/surround40:CARD=PCH,DEV=0' (HDA Intel PCH, ALC892 Analog/4.0 Surround output to Front and Rear speakers)
  'alsa/surround41:CARD=PCH,DEV=0' (HDA Intel PCH, ALC892 Analog/4.1 Surround output to Front, Rear and Subwoofer speakers)
  'alsa/surround50:CARD=PCH,DEV=0' (HDA Intel PCH, ALC892 Analog/5.0 Surround output to Front, Center and Rear speakers)
  'alsa/surround51:CARD=PCH,DEV=0' (HDA Intel PCH, ALC892 Analog/5.1 Surround output to Front, Center, Rear and Subwoofer speakers)
  'alsa/surround71:CARD=PCH,DEV=0' (HDA Intel PCH, ALC892 Analog/7.1 Surround output to Front, Center, Side, Rear and Woofer speakers)
  'alsa/iec958:CARD=PCH,DEV=0' (HDA Intel PCH, ALC892 Digital/IEC958 (S/PDIF) Digital Audio Output)
  'alsa/usbstream:CARD=PCH' (HDA Intel PCH/USB Stream Output)
  'alsa/sysdefault:CARD=DAC' (FiiO USB Audio Class 2.0 DAC, USB Audio/Default Audio Device)
  'alsa/front:CARD=DAC,DEV=0' (FiiO USB Audio Class 2.0 DAC, USB Audio/Front speakers)
  'alsa/surround21:CARD=DAC,DEV=0' (FiiO USB Audio Class 2.0 DAC, USB Audio/2.1 Surround output to Front and Subwoofer speakers)
  'alsa/surround40:CARD=DAC,DEV=0' (FiiO USB Audio Class 2.0 DAC, USB Audio/4.0 Surround output to Front and Rear speakers)
  'alsa/surround41:CARD=DAC,DEV=0' (FiiO USB Audio Class 2.0 DAC, USB Audio/4.1 Surround output to Front, Rear and Subwoofer speakers)
  'alsa/surround50:CARD=DAC,DEV=0' (FiiO USB Audio Class 2.0 DAC, USB Audio/5.0 Surround output to Front, Center and Rear speakers)
  'alsa/surround51:CARD=DAC,DEV=0' (FiiO USB Audio Class 2.0 DAC, USB Audio/5.1 Surround output to Front, Center, Rear and Subwoofer speakers)
  'alsa/surround71:CARD=DAC,DEV=0' (FiiO USB Audio Class 2.0 DAC, USB Audio/7.1 Surround output to Front, Center, Side, Rear and Woofer speakers)
  'alsa/iec958:CARD=DAC,DEV=0' (FiiO USB Audio Class 2.0 DAC, USB Audio/IEC958 (S/PDIF) Digital Audio Output)
  'alsa/usbstream:CARD=DAC' (FiiO USB Audio Class 2.0 DAC/USB Stream Output)
  'jack' (Default (jack))


 when i choose alsa/sysdefault:CARD=DAC as output i get 48kHz/ 24bit. 

6/04/2019

linux make WakeOnLan work

1. Check BIOS Settings
 
2. OS Settings


$ sudo ethtool eth0
 Settings for eth0:
 Supported ports: [ TP ]
 Supported link modes:   10baseT/Half 10baseT/Full 
                         100baseT/Half 100baseT/Full 
                         1000baseT/Full 
 Supported pause frame use: No
 Supports auto-negotiation: Yes
 Advertised link modes:  10baseT/Half 10baseT/Full 
                         100baseT/Half 100baseT/Full 
                         1000baseT/Full 
 Advertised pause frame use: No
 Advertised auto-negotiation: Yes
 Speed: 1000Mb/s
 Duplex: Full
 Port: Twisted Pair
 PHYAD: 1
 Transceiver: internal
 Auto-negotiation: on
 MDI-X: on (auto)
 Supports Wake-on: pumbg
 Wake-on: d
 Current message level: 0x00000007 (7)
          drv probe link
 Link detected: yes



Wake-on Modes:
 
p   Wake on PHY activity
u   Wake on unicast messages
m   Wake on multicast messages
b   Wake on broadcast messages
a   Wake on ARP
g   Wake on MagicPacket™
s   Enable SecureOn™ password for MagicPacket™
d   Disable (wake on nothing). This option clears all previous options.
 
 
 
change to "g Wake on MagicPacket™":


$ ethtool -s eth0 wol g


 ---------------------------------------------------------------------------------------
Change permanent:

as "/etc/rc.local" is executed while boot, just put it there:

 
$ sudo nano /etc/rc.local

#!/bin/sh -e 

# rc.local 

# This script is executed at the end of each multiuser runlevel. 
# Make sure that the script will "exit 0" on success or any other 
# value on error. 

# In order to enable or disable this script just change the execution 
# bits. 

sleep 5 
ethtool -s eth0 wol g 
exit 0 

--------------------------------------------------------------------------------------

on ArchLinux i installed wol-systemd from AUR

$ yay -S wol-systemd

 

enable & start the service:

$ systemctl enable wol@eth0

$ systemctl start wol@eth0 

____________________________________________________________________________________

 
what stopped my machine from starting via WOL:


$ sudo nano /etc/default/tlp

or

$ sudo nano /etc/tlp.conf

look for: # Disable wake on LAN: Y/N.
               WOL_DISABLE=Y
change to: WOL_DISABLE=N

11/12/2014

Ubuntu - Zyxel NSA 325 v2 - copy per USB-Bridge - mount linux_raid_member



    sudo apt-get install mdadm 

RAID0:

2 disks get connected (in Windows Explorer ass well): 

first partition got 511MB, 350MB swap, 145MB sysdisk.img

 

to see which partitionen (linux_raid_member) are needed:

sudo blkid -o list

to mount the raid:

sudo mdadm --assemble /dev/mdX /dev/sdXX /dev/sdXX  

now it's time to copy all your data.

to unmount linux_raid_member:

sudo mdadm --stop /dev/mdX 

 
After NAS-reassembling copied files to music are shown but new created directories beside the 5 already existing (admin, music, photo, public, video)  don't show up.

JBOD 2 disks 

First partition got 511MB, 350MB swap, 145MB sysdisk.img,
gets mounted (in Windows Explorer as well):

the other partition gets mounted as "md127".