Category Archives: Hosting

Delete everything multiple files Linux

If you want to find and delete some files from your drive then use this command:

find . -type f ! \( -name "*thumb.jpg" -o -name "*1200w.jpg" \) -exec rm -rf {} \;

Explanation: https://unix.stackexchange.com/questions/78376/in-linux-how-to-delete-all-files-except-the-pattern-txt

https://unix.stackexchange.com/questions/50612/how-to-combine-2-name-conditions-in-find

Adding IP address – failover ip

First edit : nano /etc/network/interfaces

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
#allow-hotplug eno1
#iface eno1 inet dhcp
 auto eno1
 iface eno1 inet static
         address 195.154.242.173
         netmask 255.255.255.255
         gateway 195.154.242.1
 auto eno1:0
 iface eno1:0 inet static
 address 51.158.26.20
 netmask 255.255.255.255

And that’s all there is actually.

Use this as a reference.

https://documentation.online.net/en/dedicated-server/network/ip-failover/ip-failover

Rsync exclude

rsync -avz files/app_akcijekatalozi –exclude=storage/ akcijekatalozi@domain.net:/home/akcijekatalozi/

Take note, exclude path storage/ is relative to files/app_akcijekatalozi path…not root path, home path or absolute path!

Installing composer on KeyHelp control panel

I’ve been trying to figure this out for the last 2 hours. But I have finally managed to install it.

From offical composer page copy paste first two lines

https://getcomposer.org/download/

like:

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === 'c31c1e292ad7be5f49291169c0ac8f683499edddcfd4e42232982d0fd193004208a58ff6f353fde0012d35fdd72bc394') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"

Then, since KeyHelp makes users folders as root you will need to use i.e. files folder for installing Composer with command above. Then use this command:

COMPOSER_HOME=/home/users/someuser/files/ php composer-setup.php

What this command does?! COMPOSER_HOME is var and enables you to write composer.phar inside different home path.

All this without root. That was the point in the first place. Root and composer are not good option.

Problem was with the permissions in the first place. Users are from root. And Composer wanted to use $cd to access home folder. It poined to /home/users/someuser (someuser is current logged in user).

Error: Unable to create Composer home directory “/home/users/someuser/.config/composer”: mkdir(): Permission denied

CPU steal time – how to check

You can easly check steal time of your VPS if you run top command and take a look at the info there.

At the end of the cpu line you should see this:

%Cpu line – end of line…it shows 0.0 st and that means it has cpu all for itself

Now, if you want to make sure steal time readings are correct use something like:

 dd if=/dev/zero | md5sum

This command will make sure your cpu is actually doing something. That way CPU steal time readings will be correct. After running this command on other vps I’m using I have got this:

Now you get the idea. This other VPS is oversold. Without using upper command I get this:

Without dd command used…no real cpu steal time

Let’s try again…

With dd command ran
Without dd command being ran

You should always make sure CPU is being used at that moment in order to get correct CPU steal time numbers…

Nick

Backup script – simple

If you want to make backups all of your server files (home dir or whatever) you should first make connection without passwords (using ssh).

First choose username you will be using like user981129, make it in server A (with backups). Then do this:

ssh-keygen -t rsa

You have now .ssh folder with public key (id_rsa.pub). Now go to the second server (server B) where backups will be transferred. Go to the /home/someuser and type:

mkdir .ssh; vi authorized_keys;

and then copy .ssh/id_rsa.pub from server A to authorized_keys.

Then on server B chmod .ssh 700; chmod .ssh/authorized_keys 640;

Then on server A make file with chmod a+x something like in /home/user981129:

vi backup.sh

and then paste this:

#!/bin/bash
NOW=$(date +"%m-%d-%Y")
SER="ip of the server where you are transfering files or nameserver"
FILE="backup.$NOW.tar.gz"
echo "Backing up data, please wait..."
rsync -avz /home/user981129/admin_backups/admin.root.admin.tar.gz someuser@ipofserverforbackup:/home/someuser/backups/$SER/$NOW/

Then open crontab -e and paste this:

0 3 * * * /home/user981129/backup.sh >/dev/null 2>&1

YOU ARE READY TO GO

edit: this post is for me, to speed things up when needed