アプリ関連ニュース

Useful Features of Rsync Command in Linux

Today, I would like to share about usefulness of rsync command in Linux and how to back up data with cron job. Let’s take a look.

Rsync (Remote Sync) is the most commonly used command for copying and synchronizing files and directories remotely as well as locally in Linux/Unix systems. Data can be copied, synchronized and backup both remotely and locally across directories, disks & networks.

Advantages of Rsync Command

  • It efficiently copies and sync files from source to destination remotely or locally.
  • It supports copying links, devices, owners, groups and permissions.
  • rsync allows to transfer just the differences between source and destination. The first time, it copies the whole content of a file or a directory from source to destination but from next time, it copies only the changed files/data to the destination.
  • Due to using compression and decompression method while transferring data, rsync consumes less bandwidth.

Installing Rsync

rsync is preinstalled on most Linux distributions and mac-OS. If rsync hasn’t been installed on the system, it can be installed easily using your distribution’s package manager as follows.

$ sudo apt-get install rsync [On Debian/Ubuntu & Mint]

$ pacman -S rsync [On Arch Linux]

$ emerge sys-apps/rsync [On Gentoo]

$ sudo dnf install rsync [On Fedora/CentOS/RHEL and Rocky Linux/AlmaLinux]

$ sudo zypper install rsync [On openSUSE]

Rsync Basic Command Syntax

Local to Local

rsync [OPTION] [SRC] [DEST]

Local to Remote

rsync [OPTION] [SRC] [USER@]HOST:DEST

Remote to Local

rsync [OPTION] [USER@]HOST:SRC [DEST]

Common options[OPTION] used with rsync commands

-v : verbose

-r : copies data recursively (but don’t preserve timestamps and permission while transferring data.

-a : archive mode, which allows copying files recursively and it also preserves symbolic links, file permissions, user & group ownerships, and timestamps.

-z : compress file data.

-h : human-readable, output numbers in a human-readable format.

For more options, the following command can be used.

$ rsync -h

For example, to backup data from local to local(external hard drive), the following command is commonly used.

rsync -azv /home/username/projects /media/username/SPHardDrive/BackupFolder

Schedule backups

To enable scheduled backups, cron can be used for the rsync commands.

Conclusion

This is all how to copy, synchronize and backup files & directories. And I recommend the link to learn more about rsync.

Hope you enjoy that.

By Asahi



Apple’s March 8 event

The next Apple event is Tuesday, March 8th. This will be a virtual event that can also be viewed from Apple’s website or Apple TV and YouTube. Today I gonna share with you some rumors expectations for this coming event.

New iPhone SE

Every few years, Apple releases a low-priced iPhone with the latest components in its old body, and this year is no exception. Apple plans to launch a third iPhone SE for $ 399, with the same iPhone 6-like design as before, but with 5G support, an improved camera, and an A15 Bionic processor.

iPhone SE
Credit: thenextweb

iPad air 5

New year, new iPad. The iPad will be equipped with an A15 chip, two additional speakers (four in total), and a 5G connection. The camera may also be improved.

Mac mini

Apple plans to announce a number of Macs this year, with at least one likely to be seen at the March 8 event. The catchphrase “Peak Performance”; and the direction is that Apple usually won’t launch high-performance mobile products until the fall.

Rumor has it that the “Mac Mini Pro” with M1 Max and M1 Pro chips is now being pointed out. After all, it doesn’t make sense for Apple laptops to be stronger than desktop products for a long time. This Mac Mini is expected to offer a slimmer and more sophisticated design.

New MacBook with M2

Apple’s M1 chip was announced in 2020. That is, you are trying to get an update. Rumor has it that the new MacBook Pro with an entry-level M2 chip should be better than the previous M1 MacBook Pro, but it doesn’t quite match the M1 Pro or Max.

To keep costs relatively low, the new MacBook Pro doesn’t have a flashy 120Hz display or Mini LED panel. The benefit of inferior screen technology is that it can avoid the dreaded notch, perhaps.

It’s also very likely that Apple will announce a redesigned MacBook Air with an M2 chip later this year, but it’s not sure.

iOS 15.4

On the software side, we are planning a release date for iOS 15.4. This is primarily a mid-cycle update and primarily includes Face ID support while wearing a mask. It also includes over 30 new emojis, non-binary Siri voice, and support for multi-device interaction with Universal Control. But most of the software might come at WWDC later this year.

Yuuma



Laravelのファイルアップロード: 重複するファイル名 – 解決するための2つの方法

今日は、ファイルのアップロードについて、特に、同じファイル名でファイルをアップロードできるようにするとどうなるか、古いファイル名を上書きしてしまうか、それをいろいろとお話したいと思います。

例えば、デフォルトで登録フォームがあり、アバターがあり、誰かがavator.jpgというファイル名でファイルをアップロードしたとします。これは正常にアップロードされているのですが、開発者がよくやるのは、ClientOriginalNameが悪意のないものであることを信じてファイル名をアップロードすることです。
しかし、元のファイル名を保持したい場合は、それは大丈夫かもしれません。しかし、同じファイル名で登録した人がいて、そのファイルがstorage/app/public/avatorsにavator.jpgとしてアップロードされた場合、問題が発生することがあります。

そして、別のユーザーで登録しようとし、ユーザー情報を入力し、異なるパスからアバターをアップロードしますが、ファイル名は同じです。登録後、古いアバターはやみくもに上書きされ、サーバーから削除されることさえあります。というわけで、これは今問題になっています。どのようにコードでそれを解決するかは、いくつかの異なる方法があります。

ということで、今からこの方法をお話ししたいと思います。

1つ目はファイル名を変更する方法です。

if ($request->file('avatar')) {
            $fileName = pathinfo($request->file('avatar')->getClientOriginalName(), PATHINFO_FILENAME) . '-' . $user->id . '.' . $request->file('avatar')->getClientOriginalExtension();

            $request->file('avatar')->storePubliclyAs('avatars', $fileName, 'public');

            $user->update([
                'avatar' => $fileName ?? null,
            ]);
        }

アベータがある場合、拡張子なしのファイル名からファイルを作成し、ユーザ登録からuser_id、そしてオリジナルの拡張子からファイルを構築することになります。そして、そのファイルをファイル名と一緒にパブリックドライバに保存し、ユーザを更新します。

2つ目はサブフォルダを作成する方法です。

$request->file('avatar')->storePubliclyAs("avatars/{$user->id}", $request->file('avatar')->getClientOriginalName(), 'public');

publicのuser_idサブフォルダに元のファイル名で保存します。

結果一覧

はい。ということで今回は以上になります。

By Ami



DataTablesを使用したテーブル生成とサーバーサイド連携(4)

今回はDataTablesを使用したテーブル生成方法とサーバーサイド連携方法の連載Part4です。
前回の記事「DataTablesを使用したテーブル生成とサーバーサイド連携(3)」で発生した問題の原因と解決の方法について紹介いたします。

続きを読む

Awesome features of PHP 8

PHP 8 has been officially released for general users. PHP 8 brings a host of new features improvements, functions, and deprecations to the language compared to PHP 7. Among all of these new features, the JIT compiler is the one sharing the limelight. However, other features like syntax changes are also to be taken into account as it is these features that will have a greater impact on the practitioners.

New features include:

  • Named arguments
  • Union types
  • Constructor property promotion
  • Custom object serialization
  • Match expression
  • Nullsafe operator
  • Improvements in the type system and error handling

New PHP Functions

  • New str_contains() function
  • New str_starts_with() and str_ends_with() functions
  • New fdiv() function
  • get_debug_type() function

str_contains()

Helps us in determining whether the given sub-string is present inside the string.

Example :

str_contains ( string $austin , string $tin ) : bool

Executes a case-sensitive operations and checks whether the string austin contains the substring tin.

 — string_starts_with and str_ends_with()

Using this function we can easily find whether the given sub-string is at the beginning or ending of the string.

Example:

str_starts_with(string $austin, string $au): bool;

str_ends_with(string $austin, string $tin): bool;

These new functions can be impersonated with strpossubstrstrncmp, and substr_compare. However, the new functions were favourably received due to its engine-level optimizations and their regular use cases.

fdiv()

The new fdiv() function has similar ability as the fmod() and intdiv() functions, that allows for division by 0. Instead of getting errors, you’ll get INF, -INF, or NAN, depending on the scenario.

get_debug_type()

The new get_debug_type function always returns the true native type of variables. It returns a return native type names, e.g., int rather than integer, double instead of float.

get_debug_type() function helps in

  • Error reporting
  • Debugging
  • Business logic
  • By Tsuki



    アプリ関連ニュース

    お問い合わせはこちら

    お問い合わせ・ご相談はお電話、またはお問い合わせフォームよりお受け付けいたしております。

    tel. 06-6454-8833(平日 10:00~17:00)

    お問い合わせフォーム