PowerShell – Ordenar arquivos

gci . -r | sort Length -desc | select fullname -f 10

Get-ChildItem -Path c:\ -Recurse | Sort-Object Length -Descending | Select-Object length,name,directory -First 100 | Format-Table -AutoSize

Referencias:

  • How do I find the 10 largest files in a directory structure
    • https://stackoverflow.com/questions/798040/how-do-i-find-the-10-largest-files-in-a-directory-structure
  • Sort Files by Size PowerShell
    • https://gist.github.com/tomarbuthnot/1c148a3ad09641f6313d

Utilitários unidos – inotifywait and grep

#!/bin/bash
#
#    Copyright (C) 2017 Leonardo Serra 
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see .
#

echo $((2**24)) > /proc/sys/fs/inotify/max_user_watches

inotifywait -m -r -e modify --format '%w%f' /var/www| while read FILE
do
  case $FILE in
    *.php*)
#      echo 'Scanning file '$FILE' ...'
      if /bin/grep -q 'create_function' $FILE
      then
        date=`date '+%Y/%m/%d %H:%M:%S'`
        echo $date' Found create_function at file: '$FILE
      fi
  esac
done

Docker and Debian

Referencias:

  • Get Docker CE for Debian
    • https://docs.docker.com/install/linux/docker-ce/debian/
  • Docker and Debian
    • https://wiki.debian.org/Docker
  • Automating the creation of docker images
    • https://debian-administration.org/article/698/Automating_the_creation_of_docker_images

Google Cloud – Set instance hostname/FQDN

Create/edit metadata of instance at:

https://console.cloud.google.com/compute

To use the patch bellow, you need to create a metadata with key name hostname, set this to your hostname/FQDN.

Connect to instance (by SSH) and apply this patch to file /etc/dhcp/dhclient-exit-hooks.d/google_set_hostname

--- before/etc/dhcp/dhclient-exit-hooks.d/google_set_hostname 2018-03-31 04:35:36.482261558 +0000
+++ after/etc/dhcp/dhclient-exit-hooks.d/google_set_hostname 2018-03-31 03:34:44.528862484 +0000
@@ -15,6 +15,10 @@
 
 # Deal with a new hostname assignment.
 
+# https://gist.github.com/yuki-takeichi/3080521322f0f1d159ea6a343e2323e6
+# *** The below line is added by patching. ***
+new_host_name=$(curl --fail --silent http://metadata/computeMetadata/v1/instance/attributes/hostname -H "Metadata-Flavor: Google")
+
 if [ -n "$new_host_name" ] && [ -n "$new_ip_address" ]; then
 # Delete entries with new_host_name or new_ip_address in /etc/hosts.
 sed -i '/Added by Google/d' /etc/hosts

To avoid lose the  patch, use this command:

# dpkg-divert --add /etc/dhcp/dhclient-exit-hooks.d/google_set_hostname

Now, reboot the instance to apply the FQDN set in metadata.

# reboot

Referencias:

Migrando e Instalando GitLab

Neste documento vamos migrar um GitLab do tipo CE / Edição 9.5.3 , porem outros tipos/edições podem ser utilizadas

Servidor antigo (192.168.0.x)

$ sudo gitlab-rake gitlab:backup:create

Em nosso exemplo, dentro da pasta /var/opt/giblab/backups do servidor antigo, foi criado um arquivo com o nome  1519781652_2018_02_27_9.5.3_gitlab_backup.tar

Copie o arquivo 1519781652_2018_02_27_9.5.3_gitlab_backup.tar para o novo servidor (IP 192.168.0.y) . Em nosso caso usamos o comando scp para copiar usando SSH com usuario chamado user_ssh.

$ sudo scp /var/opt/giblab/backups/1519781652_2018_02_27_9.5.3_gitlab_backup.tar user_ssh@192.168.0.y:/var/opt/giblab/backups

Também copie os arquivos /etc/gitlab/gitlab.rb e /etc/gitlab/gitlab-secrets.json para o novo servidor usando os seguintes comandos:

$ sudo scp /etc/gitlab/gitlab.rb user_ssh@192.168.0.y:/etc/gitlab/gitlab.rb
$ sudo scp /etc/gitlab/gitlab-secrets.json user_ssh@192.168.0.y:/etc/gitlab/gitlab-secrets.json

Servidor novo (IP 192.168.0.y)

Primeiro etapa é a instalação do GitLab correto. É necessário escolher para a instalação o mesmo tipo (CE/EE) e a mesma versão para o backup poder ser restaurado corretamente.

Escolha abaixo o comando adequado para a instalação do GitLab de acordo com o sistema operacional de seu ambiente.

Comandos para instalar em servidor com Sistema Operacional Debian 9 (stretch):
$ curl -s https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash
$ sudo apt-get install gitlab-ce=9.5.3-ce.0
$ gitlab-ctl reconfigure
Comandos para instalar em servidor com Sistema Operacional CentOS 7:
$ curl -s https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
$ sudo yum install gitlab-ce-9.5.3-ce.0.el7.x86_64
$ gitlab-ctl reconfigure
Abaixo os comandos para restaurar o backup criado no servidor antigo:
$ sudo gitlab-ctl stop unicorn
$ sudo gitlab-ctl stop sidekiq
$ sudo gitlab-rake gitlab:backup:restore BACKUP=1519781652_2018_02_27_9.5.3
$ sudo gitlab-ctl restart
$ sudo gitlab-rake gitlab:check SANITIZE=true

Referencias

Teste de desempenho em rede TCP/IP

Serão considerando dois Hosts (A e B) durante a realização deste teste. O objetivo deste teste é medir a taxa de transferência capaz de ser atingida pela conectividade que une estes dois Hosts.

Sera necessário instalar o utilitário netcat no Host A e no Host B, para isto execute o seguinte comando (como usuário administrador/root) em cada um dos hosts:

# apt install netcat-traditional

Execute no Host A (IPv4 192.168.0.1):

$ nc -l -p 12345

Execute no Host B (IPv4 192.168.0.2):

$ dd if=/dev/zero | nc 192.168.0.1 12345

Após executar o comando no Host B, aguarde ao menos de  1  a 2 minutos e realize um CTRL+C no Host B.

Resultado no Host B,  após 3 minutos:

4053175+0 registros de entrada
4053174+0 registros de saída
2075225088 bytes (2,1 GB) copiados, 182,638 s, 11,4 MB/s

A taxa de transferência obtida durante este teste foi de 11,4 MB/s.